Coproject - a RIA Caliburn.Micro demo, part 2
2015-09-03 06:54
302 查看
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.
In Coproject.Web, create a new folder called Models.
Add a new Entity Data Model called CoprojectModel to it.
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb.png)
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:
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_4.png)
Click Finish and wait for the model being created. Then rebuild the solution. Now, the server is able to access database.
Create a folder called Services and add new Domain Service Class called CoprojectService to it.
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_2.png)
Then, set the wizard as follows:
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_3.png)
Two new files should be added to Services:
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_5.png)
The first file contains the RIA service itself. You can see functions like GetToDoItems, InsertToDoItem, etc. Their purpose should be clear.
The other file called CoprojectService.metadata.cs contains several classes like:
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:
This will make RIA services to link proper entites into the respective references. The same has to be done for ToDoListMetadata:
Build the solution to make sure that there are no errors. Now, the server side is ready to serve data for client.
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.
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb.png)
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:
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_4.png)
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.![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_2.png)
Then, set the wizard as follows:
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_3.png)
Two new files should be added to Services:
![](http://www.baud.cz/Media/Windows-Live-Writer/CoProject---a-RIA-Cali.Micro-demo-part-2_117B8/image_thumb_5.png)
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 3
- Coproject - a RIA Caliburn.Micro demo, part 4
- Coproject - a RIA Caliburn.Micro demo, part 5
- Coproject - a RIA Caliburn.Micro demo, part 6
- Coproject - a RIA Caliburn.Micro demo, part 7
- Coproject - a RIA Caliburn.Micro demo, part 8
- Coproject - a RIA Caliburn.Micro demo, part 9
- Coproject - a RIA Caliburn.Micro demo, part 10
- Coproject - a RIA Caliburn.Micro demo, part 11
- 我是如何利用1条百度知道给网站日引流破万的?
- Coproject - a RIA Caliburn.Micro demo, part 10.5
- Coproject - a RIA Caliburn.Micro demo, part 12
- Coproject - a RIA Caliburn.Micro demo, part 14
- Coproject - a RIA Caliburn.Micro demo, part 13
- Nginx 配置常见误区
- Linux学习之grep篇
- Hadoop学习计划
- Clustered Shading架构实现步骤
- wcf利用IDispatchMessageInspector实现接口监控日志记录和并发限流
- Nginx的作用