Coproject - a RIA Caliburn.Micro demo, part 2
来源:互联网 发布:罗曼电动牙刷知乎 编辑:程序博客网 时间:2024/05/21 22:37
In this part, we will create a domain model and a RIA service so that the client application will be able to access data in Coproject database.
For those of you, who would like to see the code running but don't have time to write it, check Coproject codeplex site.
1. Create domain model
In Coproject.Web, create a new folder called Models.
Add a new Entity Data Model called CoprojectModel to it.
In Entity Data Model Wizard, choose Generate from database. Choose the proper database connection (probably Database.mdf) and let VS to Save entity connection settings in Web.Config as CoprojectEntities. Finally set the last wizard step as follows:
Click Finish and wait for the model being created. Then rebuild the solution. Now, the server is able to access database.
2. Create RIA service
Create a folder called Services and add new Domain Service Class called CoprojectService to it.
Then, set the wizard as follows:
Two new files should be added to Services:
The first file contains the RIA service itself. You can see functions like GetToDoItems, InsertToDoItem, etc. Their purpose should be clear.
Set metadata
The other file called CoprojectService.metadata.cs contains several classes like:
internal sealed class ToDoListMetadata{ // Metadata classes are not meant to be instantiated. private ToDoListMetadata() { } public DateTime CreatedDate { get; set; } public string Description { get; set; } public string Name { get; set; } public Nullable<int> ProjectID { get; set; } public EntityCollection<ToDoItem> ToDoItems { get; set; } public int ToDoListID { get; set; } public Nullable<DateTime> UpdatedDate { get; set; }}
These are metadata that describe what entities should be transferred to the client, what links are between them, how to localize labels for these properties or how to validate them. Take this as a configuration file for the RIA service. These settings, although written on server, are transferred by RIA Services to the client application and available there too. Now, we have to add some more metadata.
Add attribute [Key] to properties ToDoItemMetadata.ToDoItemID, and ToDoListMetadata.ToDoListID and UserMetadata.UserID. This will instruct RIA Services that these properties are primary keys for these classes. This is essential for updating data and handling links between entities.
Next, update other properties of ToDoItemMetadata to look like:
[Include][Association("FK_ToDoItems_ToDoLists", "ToDoListID", "ToDoListID", IsForeignKey = true)]public ToDoList ToDoList;[Include][Association("FK_ToDoItems_Users", "UserID", "UserID", IsForeignKey = true)]public User User;
This will make RIA services to link proper entites into the respective references. The same has to be done for ToDoListMetadata:
[Include][Association("FK_ToDoItems_ToDoLists", "ToDoListID", "ToDoListID")]public EntityCollection<ToDoItem> ToDoItems;
Build the solution to make sure that there are no errors. Now, the server side is ready to serve data for client.
- Coproject - a RIA Caliburn.Micro demo, part 2
- Coproject - a RIA Caliburn.Micro demo, part 13
- Coproject - a RIA Caliburn.Micro demo, part 14
- Coproject - a RIA Caliburn.Micro demo, part 12
- Coproject - a RIA Caliburn.Micro demo, part 10.5
- Coproject - a RIA Caliburn.Micro demo, part 11
- Coproject - a RIA Caliburn.Micro demo, part 10
- Coproject - a RIA Caliburn.Micro demo, part 9
- Coproject - a RIA Caliburn.Micro demo, part 8
- Coproject - a RIA Caliburn.Micro demo, part 7
- Coproject - a RIA Caliburn.Micro demo, part 6
- Coproject - a RIA Caliburn.Micro demo, part 5
- Coproject - a RIA Caliburn.Micro demo, part 4
- Coproject - a RIA Caliburn.Micro demo, part 3
- Coproject - a RIA Caliburn.Micro demo, part 1
- Coproject - a RIA Caliburn.Micro demo, part 0
- Caliburn Micro Part 2: Data Binding and Events
- Caliburn Micro Part 1: Getting Started
- Coproject - a RIA Caliburn.Micro demo, part 5
- Coproject - a RIA Caliburn.Micro demo, part 4
- 图解Linux命令之--tr命令
- Coproject - a RIA Caliburn.Micro demo, part 3
- 关于计算机辅助“发明”(CAI)的设想
- Coproject - a RIA Caliburn.Micro demo, part 2
- Coproject - a RIA Caliburn.Micro demo, part 1
- Coproject - a RIA Caliburn.Micro demo, part 0
- GO语言学习笔记2(指针数组MAP)
- 关于计算机辅助“发明”(CAI)的设想
- Java前面基础知识
- 统计与推断
- 生产者与消费者
- 如何才能做到像gephi那样社区划分可视化呢?