locked
EF POCO Change Tracking classes for client entity classes RRS feed

  • Question

  • Hi

    I use EF4 POCOs with Change Tracking. I put the entities in a seperate Assembly which the client also use (as described in MSDN). Now i use WCF Data Services only for query purposes - for saving / changing i use WCF functions (because of special signatures with special addional information and so on).

    The problem is, that if i consume the WCF Data Service on client side, it creates its own POCO classes :-( Is there a way to use my EF POCO classes so that WCF Data Services use them too for query stuff and that i can use WCF for saving?

    Thanks a lot
    Michael

    PS: I only want a way to query data on the client. If something like GetAllCustomers(c => c.Name == "Joe") is also possible - i would prefer it (but expression tress arent serializable :-((( Maybe there is a way write a custom expression builder GetAllCustomers(Filter.Where.Like(Name, "Joe")) and convert it on server side? Anybody knows?

     

    Friday, November 12, 2010 9:43 AM

Answers

  • Hi,

    EF 4 Self Tracking Entities are not very friendly with our Data Services client, namely, the client type will contain the tracker property because we do not look at the EF attributes (like ignore property). It's recommended that you use the client-side code-gen to access data on the client side. 

    As I understand you are trying to use WCF service plus client side EF Self Tracking Entities for saving changes, but want to populate the entities with WCF Data services. This is actually possible, you should be able to add reference to the assembly containing your EF STE classes + System.Data.Services.Client.dll, then just do:

    var q = dataServiceContext.CreateQuery<MyEntity1>("EntitySet").Where(c=>c.Name == "Joe");

    you don't need to serialize this query, the client library will turn it into an URI and call the service with it. It should also materialize the results into your entity object.

    Keep in mind that the moment you do update with these objects using the data service context, you'll encounter errors related to the tracker property not being able to serialize.

    Finally, I would suggest you look into pure data service solution. Is there something in particular that's blocking you from using data services to track changes? What are the "Special signatures with special addional information"?

    Regards,

    PQ


    Peter Q. http://blogs.msdn.com/peter_qian
    Friday, November 12, 2010 11:14 AM
    Answerer

All replies

  • Hi,

    EF 4 Self Tracking Entities are not very friendly with our Data Services client, namely, the client type will contain the tracker property because we do not look at the EF attributes (like ignore property). It's recommended that you use the client-side code-gen to access data on the client side. 

    As I understand you are trying to use WCF service plus client side EF Self Tracking Entities for saving changes, but want to populate the entities with WCF Data services. This is actually possible, you should be able to add reference to the assembly containing your EF STE classes + System.Data.Services.Client.dll, then just do:

    var q = dataServiceContext.CreateQuery<MyEntity1>("EntitySet").Where(c=>c.Name == "Joe");

    you don't need to serialize this query, the client library will turn it into an URI and call the service with it. It should also materialize the results into your entity object.

    Keep in mind that the moment you do update with these objects using the data service context, you'll encounter errors related to the tracker property not being able to serialize.

    Finally, I would suggest you look into pure data service solution. Is there something in particular that's blocking you from using data services to track changes? What are the "Special signatures with special addional information"?

    Regards,

    PQ


    Peter Q. http://blogs.msdn.com/peter_qian
    Friday, November 12, 2010 11:14 AM
    Answerer
  • Hi Peter

    Sorry for the late reply - had lots of work. And thanks a lot for your reply

    I tried to modify the EF4 Poco Self Tracking T4 script so that it adds "System.Data.Services.Common.DataServiceKeyAttribute" and some other functions which are needed by WCF Data Service client. But it sheems to be an endless game :-S

    "Is there something in particular that's blocking you from using data services to track changes?"

    I have to mention that i havent read the documentation details - but the examples i saw allow the client to manipulate data without passing some business logic on the server side (i found Interceptors - but thats "jails" me in what i want to do). Is there a way to use the "classic" n-tier architecure (as described in MS architecture guide) with WCF Data Services? (putting a business layer on server side between storage [EF4] and service).

    I found also a other nice way: http://marcinbudny.blogspot.com/2008/11/using-metalinq-to-simulate-nhbernates.html

    I'm not quite sure if this limits me in what i want to achive - but it allows me to do "GetAllCustomers(c => c.Name == "karl")"

    Is there a recommendation from Microsoft how to do such queries like "GetAllXXXX"?

    Thanks a lot

    Michael

     

     

     

    Thursday, November 18, 2010 6:39 PM