开发者

What's the best POCO status tracking strategy? (EF)

So I was reading about Entity Framework and based on my agile development scenario I decided to go with POCO objects.

But now I'm having some extra problems I don't know how to get away with.

I'm working with RIA services and Silverlight so when I'm going to Save an object of the server side I have to attach the object to an ObjectContext. The thing is that I must then change the ObjectState to Added or Modified.

So my question is what's the best approach to really know what state to change it to. I saw in Julia Lerman's book that she uses a State attribute in her POCO objects and she takes care managing that state on the client side before sending the object to the server. That state then is used to change the real EntitySate once attached.

I've also seen other samples where the Insert implementation checks on the Key of the Entity (object) to know whether it is new or not. For example, if ProjectId in my Project entity is 0 (zero) I know it has to be a new object.

To be honest I don't like any of those approaches because in 开发者_Go百科both cases my developers have to do some extra-work to actually save the object.

I'd like the know pros and cons of both solutions and hopefully a new (better) solution I'm still not seing.


You can still have self tracking entities and poco. In visual studio if you search the community templates there is a self tracking poco template. this is what you want to use. If you can find the template look for your entities using Ientitywithobjecttracker.

http://msdn.microsoft.com/en-us/library/dd456848.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜