EF 4 Self Tracking Entities does not work as expected

前端 未结 5 1216
不思量自难忘°
不思量自难忘° 2021-01-25 18:16

I am using EF4 Self Tracking Entities (VS2010 Beta 2 CTP 2 plus new T4 generator). But when I try to update entity information it does not update to database as expected.

<
相关标签:
5条回答
  • 2021-01-25 18:57

    If you are using STEs without WCF you may have to call StartTracking() manually.

    0 讨论(0)
  • 2021-01-25 18:58

    This is probably a long shot... but:

    I assume your Service is actually in another Tier? If you are testing in the same tier you will have problems.

    Self Tracking Entities (STEs) don't record changes until when they are connected to an ObjectContext, the idea is that if they are connected to a ObjectContext it can record changes for them and there is no point doing the same work twice.

    STEs start tracking once they are deserialized on the client using WCF, i.e. once they are materialized to a tier without an ObjectContext.

    If you look through the generated code you should be able to see how to turn tracking on manually too.

    Hope this helps

    Alex

    0 讨论(0)
  • 2021-01-25 19:07

    You have to share assembly with STEs between client and service - that is the main point. Then when adding service reference make sure that "Reuse types in referenced assemblies" is checked.

    The reason for this is that STEs contain logic which cannot be transfered by "Add service reference", so you have to share these types to have tracing logic on client as well.

    0 讨论(0)
  • 2021-01-25 19:13

    After reading the following tip from Daniel Simmons, the STE starts tracking. Here is the link for the full article. http://msdn.microsoft.com/en-us/magazine/ee335715.aspx

    Make certain to reuse the Self-Tracking Entity template’s generated entity code on your client. If you use proxy code generated by Add Service Reference in Visual Studio or some other tool, things look right for the most part, but you will discover that the entities don’t actually keep track of their changes on the client.

    so in the client make sure you don't use add service reference to get the proxy instead access service through following code.

    var svc = new ChannelFactory<IMyService>("BasicHttpBinding_IMyService").CreateChannel();
    var res = svc.GetResource(1);
    
    0 讨论(0)
  • 2021-01-25 19:14

    I had the same exact problem and found the solution.

    It appears that for the self-tracking entities to automatically start tracking, you need to reference your STE project before adding the service reference.

    This way Visual Studio generates some .datasource files which does the final trick.

    I found the solution here: http://blogs.u2u.be/diederik/post/2010/05/18/Self-Tracking-Entities-with-Validation-and-Tracking-State-Change-Notification.aspx

    As for starting the tracking manually, it seems that you do not have these methods on the client-side.

    Hope it helps...

    0 讨论(0)
提交回复
热议问题