Use EF to generate the data model and then modify the data directly in the database, and the data is unchanged after the foreground refresh

Source: Internet
Author: User

SL5+WCF Ria +ef

Beginner level

After SQL Server manually modified the database data, and then to the foreground to refresh the data, found that the data has not changed, the service side return and the foreground inconsistency

Service-side code

Public iqueryable<customer> Getcustomerbycustomerid (string customerId)
{

return this. ObjectContext.Customer.Where (E = E.customid = = customerId);
}

Client Update button Code

private void Button_Click (object sender, RoutedEventArgs e)
{

Customercontext.load<customer> (Customercontext.getcoustomerbycustomeridquery ("000001")). Completed + = (s, x) = =
{
Customer = (Customer) ((loadoperation<customer>) s). Entities.firstordefault ();
MessageBox.Show (Customer. Customname + customer. Address);
};
}

For example, the CustomerName and customeraddress of number 000001 have been modified

View return data in the background

Data obtained at the front desk

The reason cannot be clearly expressed, it should be related to the persistence context of EF

A temporary solution

Call the Entitycontainer.clear () method of the context Customercontext before invoking the background service

Hope that in-depth study of EF can improve, but also hope that the specific reasons for you

Use EF to generate the data model and then modify the data directly in the database, and the data is unchanged after the foreground refresh

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.