- Manage NuGet packages, add entity Framework for projects
- Entity that establishes the model corresponding table
- Create a new DbContext class that inherits the DbContext
- The DbContext class plus the properties of the table, how many properties are written on the number of tables
- The type of the property is represented by idbset<>
- Entity Write ID, type is GUID type
- A handle to the new DbContext class is used first
- Use the handle can do additions and deletions and other operations
1 Public class Dbtestcontext:dbcontext 2 {3public getset;} 4 Public Get Set 5 }
DbContext
1 Public classUser2 {3 PublicGuid Id {Get;Set; }4 Public stringName {Get;Set; }5 6 PublicGuid CompanyID {Get;Set; }7 PublicCompany Company {Get;Set; }8 9}
User
1 varEF =NewDbtestcontext ();2 3 //var C = new company ()4 //{5 //Id = Guid.NewGuid (),6 //Name = "NX"7 //};8 //var u = new User ()9 //{Ten //Id = Guid.NewGuid (), One //Name = "My Oh Da", A //CompanyID = c.id, - //}; - //EF. Users.add (u); the //Ef.Companies.Add (c); - - varDF = fromUinchEF. Users - whereU.company.name = ="NX" + Selectu; - varFDDF =DF. ToList (); + A varDFE = fromUinchEF. Users atJoin Cinchef.companies on U.companyid equals c.id - whereC.name = ="NX" - Selectu; - varFesi =DfE. ToList (); - -Ef. SaveChanges ();
How to use
EF Simple Example Entity Framework