Diligence. NET 4.0 (9)

Source: Internet
Author: User

Introduced

Ado.net Entity Framework 4.1 new features: Code a

Example

Web.config

<?xml version= "1.0"?>
<configuration>
<connectionStrings>
<!--
You need to set the Persist security info to True to save password information
Because Database.setinitializer<mycontext> (new dropcreatedatabaseifmodelchanges<mycontext> ()); You need to connect to the master library to determine if Code A is consistent with the database structure
-->
<add name= "myconnection" providername= "System.Data.SqlClient" connectionstring= "server=".; database=mydb;uid=sa;pwd=111111; Persist Security Info=true "/>
</connectionStrings>
</configuration>

Global.asax.cs

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.SessionState;
Using System.Data.Entity;
Using EF41. Codefirst;
Namespace EF41
{
public class Global:System.Web.HttpApplication
{
protected void Application_Start (object sender, EventArgs e)
{
When code A is inconsistent with the database structure, delete the original database and regenerate the new database structure based on code
Database.setinitializer<mycontext> (New dropcreatedatabaseifmodelchanges<mycontext> ());
Don't do anything.
Database.setinitializer<mycontext> (NULL);
}
}
}

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.