asp.net mvc - How to view the code of an ADO.NET Entity Data Model -


i created ado.net entity data model. can go check actual class? want check data types , add displayname attributes.

here model solution explorer:

enter image description here

thanks.

when generate model database (which appears case here), few different code files created. code context, expand programmasterlist.context.tt. you'll see .cs file in there context class.

then, each table selected database part of model, entity class created. can find expanding programmasterlist.tt. instance, if have table called person, might have entity class file person.cs person class defined in it.

now, mentioned wanting modify classes add properties. if modify class files under programmasterlist.tt, dynamically generated entity framework, next time update model database (such add new table db model), changes you've made overwritten. fortunately, there's better way. each class under programmasterlist.tt partial class. so, can add class without modifying file entity framework automatically generated. create new file, declare person class (as partial), , add methods, properties, etc. in there. i'd suggest putting such "extensions" folder keep them organized, that's you.

so, might this:

solution structure:

  • programmasterlist.edmx
    • programmasterlist.context.tt
      • programmasterlist.context.cs
    • programmasterlist.designer.cs
    • programmasterlist.edmx.diagram
    • programmasterlist.tt
      • person.cs
  • extensions
    • person.cs

person.cs (under programmasterlist.tt)

//------------------------------------------------------------------------------ // <auto-generated> //     code generated template. // //     manual changes file may cause unexpected behavior in application. //     manual changes file overwritten if code regenerated. // </auto-generated> //------------------------------------------------------------------------------  namespace somenamespace {     using system;     using system.collections.generic;      public partial class person     {         public person()         {         }          public int personid { get; set; }         public string name { get; set; }         public datetime birthdate { get; set; }     } } 

person.cs (in extensions folder) note: make sure namespace matches namespace other person.cs file.

namespace somenamespace {     public partial class person     {         // custom property (not auto-generated entity framework)         public string displayname         {             { return personid + " - " + name + " (" + birthdate.tostring() + ")"; }         }     } } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -