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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -