Considerations for using WCF and EF

Source: Internet
Author: User

1. The poco class must be passed by WCF and cannot be referenced cyclically (you can add [datacontract (isreference = true)] to the object class)

2. One problem is the delayed loading of EF and the proxy instance mechanism. As a result, the EF query result is not a poco class, but a proxy class,

EF proxy instance mode: configuration. proxycreationenabled = false;

How to Implement the updateuser method is usually updated using the idbset. Attach () method.

M_dbset.attach (entity );
This. dbcontext. Entry <t> (Entity). State = entitystate. modified;
This. dbcontext. savechanges ();

However, you will find that, because EF has disabled proxycreationenabled to support the WCF Service, the attach method here cannot be executed successfully in any case,

At this time, you will think, I will not use the attach method, delete the object first, and then re-Add the row,

No no. Because EF automatically modifies the data table based on the object relationship during savechanges, When you delete a user, the records in the User table and user_role table will be deleted, if the user object is added, the user and user_role tables will be added to the user table, and the role table will be added to the role table (because the user. roles ),

At this time, you will find that adding a role to the role table will not work, because the record already exists; so this method cannot solve the problem well !!

What should I do? I don't know what to do for the moment, so I am here to ask for help ~~ Let's see what experience we have and how to deal with it!

PS: Data Services and RIA services are not considered for the moment, because my application needs to authorize specific operations! Non-web System!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.