I. SQL Server database creation table company, containing id,cname,isenabled three columns
Two. (1) vs Create a new Dxapplication project, named Companymanagesystem
(2) Under Project, right click "Manage NuGet Package", "Browse", "EntityFramework", click "Install"
(3) Create a new class PSContext.cs
Namespace companymanagesystem{ class Pscontext:dbcontext {public pscontext (): Base ("Name= Pscontext ") {} public virtual dbset<company> companys {get; set;} protected override void onmodelcreating (dbmodelbuilder modelBuilder) { }} }
(4) Create a new class Company.cs
namespace companymanagesystem.model{ [Table ("Company")] public class company { public Guid ID {get; set;} Public String CName {get; set;} public bool IsEnabled {get; set; }}}
(5) Code to add a database in app. Config
<?xml version= 1.0 " Encoding=" utf-8 "?><configuration> <connectionStrings> <add name=" pscontext " connectionstring=" data source=x450v-pc;initial catalog=date;integrated security=true; Multipleactiveresultsets=true; App=entityframework providername=" system.data.sqlclient "/> </connectionstrings></configuration>
(6) Add the form Frm_showinfo.cs (note: The name in the Filedname is the same as the column name of the database, (name) inside the name to try not to take name)
To add a control:
namespace companymanagesystem{ Span style= "color: #0000ff;" >public partial class Frm_showinfo:form {Pscontext _db = new Pscontext (); public Frm_showinfo () {Initia Lizecomponent (); private void frm_showinfo_load (object sender, EventArgs e) {Compan Ygrid.datasource = _db.companys.asnotracking (). ToList (); } }}
(7) Start Frm_showinfo.cs window in Program.cs
namespacecompanymanagesystem{Static classProgram {/// <summary> ///The main entry point for the application. /// </summary>[STAThread]Static voidMain () {application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Bonusskins.register (); Skinmanager.enableformskins (); UserLookAndFeel.Default.SetSkinStyle ("DevExpress Style"); Application.Run (Newfrm_showinfo ()); } }}
C #------entityframework entity Load Database