开发者

Which is proper way to create PresentationModel in Silverlight RIA Service?

开发者 https://www.devze.com 2023-03-08 16:16 出处:网络
I have search employee page and edit employee date. User can search data in employee search page and it will show first name and last name of employee, so I create SearchEmployeeEntity in my presentat

I have search employee page and edit employee date. User can search data in employee search page and it will show first name and last name of employee, so I create SearchEmployeeEntity in my presentation model. When user click edit employee, I will get data from service, this time I get first name, last name, username, birthday and other informations, so I create another presentation model name EmployeeEntity.

I think about my design for a while, there are two way to doing this, one is as I just explain above, other is use only one presentation model (EmployeeEntity) in both service.

Anyway, if I use EmployeeEntry in all place (search page and edit page) it's quite hard to manage data since I use static DomainContext.

Please suggest me,开发者_如何学运维 which way is good to create presentation model in Silverlight Application?

P.S. I use MVVM at my client.


It's the same entity so you should only need one. What's different is the context in which it is used - either you're creating a new Employee, or editing an existing one.

Silverlight RIA Services will handle this for you as it knows how to perform change tracking.

So, when you are editing, you will do a lookup against your context and perform a LoadOperation, which will return the entity to you from the DB. Allow the user to edit fields of the Employee on the clients ide, and then perform a SubmitOperation to persist the changes to the DB.

For new Employees, you create a new EmployeeEntity in your ViewModel, and then add it to the Context's Employees collection. Like so:

EmployeeContext.Employees.Add(Employee);

When the fields are filled out correctly (and hopefully you're taking advantage of Silverlight's super-easy validation rules to ensure correct data) then you, again, perform a SubmitOperation to save the new entity to the DB.

0

精彩评论

暂无评论...
验证码 换一张
取 消