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);
}
}
}