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

  1. why practicecontext partial class?
  2. 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

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

android - Unable to generate FCM token from dynamically instantiated Firebase -