views:

201

answers:

1

I have POCO's in a separate project and now I need Self Tracking Entities. Does anyone know if I need to generate new POCO's that are self tracking and they will replace my current POCO's? Or, do I setup self tracking entities in addition to my current POCO's?

Thanks!

+1  A: 

You do not need both. STE is essentially POCO with additional capability for change tracking when disconnected from the ObjectContext. I would suggest that you stick with STE if you have n-tier scenario. For non N-Tier scenario meaning when you are working with your entities on the server side, you can use it like a poco object and let ObjectContext manage change tracking for you.

zeeshanhirani
I have a custom Object Context that inherits ObjectContext object. Can I still use that?
Dan H
I have a combination of both. Some of the clases I need to add business logic too and I can't add it to the generated code so I'm using partial classes to make it work. Thanks!
Dan H
You should be fine with adding partial classes to Self Tracking Entity. As i said, it is really nothing more then POCO with its own change tracking capabilities. Only thing that you would get with pure poco is lazy loading if you have proxies turned on. This is something you won't get if you are using STE.
zeeshanhirani
So if I have a User object that has a Company property which is a company object. Every time I load User it's going to load the Company object as well? Will it also load all of the Companies properties that are other objects? BTW - I like your book. It's been helpful.
Dan H
No EF only loads entities that you request. so if u requested User, that's all you will get. However with lazy loading feature, when you do user.Company, at that moment company object will be fetched. If you do not like this automatic lazy loading when you access a property, you can turn it off by doing context.ContextOptions.LazyLoadingEnabled=false
zeeshanhirani
That's what I thought. So with the STE's I'll need to use Include to get my other objects to load. Correct? Otherwise, I'm guessing, they'll be null?
Dan H
Also, I'm using IObjectSet and it doesn't have ApplyChanges()....How do I use that with IObjectSet??
Dan H
with STE you can either use Include or LoadProperty method on the ObjectContext.
zeeshanhirani