In app. Config, you can:
(1) Custom classes
Public Xxxxdbcontext ()
{
Public Xxxxdbcontext (): Base ("Name=xxxxcontainer")//This is something that points to its connection string
{
}
protected overrride void onmodelcreating (Dbmodelbuilder modelBuilder)
{
}
Pulbic dbset<model1> Model1{get;set;}
Public dbset<model2> Model2 {get;set;}
}
(2) Model1 and Model2 write their own
public class Model2
{
[Key]
public int id{get;set;}
public virtual Model1 Model1{get;set;}
}
(3) Add EF related references, note that in the new version of VS, the referenced assemblies are placed in the Packages folder under the project
(4)
<configuration>
<connectionStrings>
<add name= "Xxxxcontainer" connectionString = "Server=localhost;userid =root;password=123;persist Security Info = True;database=dbname;charset=utf8; "
Providername= "Mysql.Data.MysqlClient" >//if it is SQL Server, then System.Data.SqlClient
</...>
</...>
(5) Write code
* CREATE DATABASE dynamically
DbContext.Database.CreateIfNotExists ();
//
Learn notes 33_ef cross-database