c# - Why is EDM class a partial class -
i added new ado.net edm item in visual studio porject.
using system; using system.data.entity; using system.componentmodel.dataannotations.schema; using system.linq; using system.diagnostics; namespace rajat.personal.ef { public partial class practicecontext : dbcontext { public practicecontext() : base("name=localcontext") { this.database.log = s => debug.writeline(s); } public virtual dbset<user> users { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<user>() .property(e => e.firstname) .isunicode(false); modelbuilder.entity<user>() .property(e => e.lastname) .isunicode(false); modelbuilder.entity<user>() .property(e => e.emailaddress) .isunicode(false); modelbuilder.entity<user>() .property(e => e.password) .isunicode(false); } }
}
i have 2 questions
- why practicecontext partial class?
- why users property virtual ?
it generated partial class
can extend class in separate file , avoid losing edits you've made when context next regenerated.
it uses virtual
on properties can override them in inherited class provide alternative behaviour.
Comments
Post a Comment