c# - How to write a DbContext Class. -
If I have a database named STOREitems, and I have that table heading values in the table, and the name of the model will be value Can I write something like this?
Public class STOREitemsDBContext: DbContext {public DbSet
I have worked through an MVC tutorial and now I am trying to work on my own with the already existing database, which I have access to The tutorial did not make it clear how to write the DB reference class, he just gave it to me and said what it does.
If you are going to use an existing database, then you have to close your database unprecedented. Reference
Public category StoreItemsContext: DbContext {Public StoreItemsContext (): Support ("YourConnectionStringName") {Database.SetInitializer & LT; StoreItemsContext & gt; (Zero); } // DBSet publishes DBSET and Lieutenant here; Price & gt; Prices {Get; Set; }}
Note: Class and property names should be camel-seated with firstly cached characters.
If your table name doesn not match the basic unit framework conference with the name of the entity class, plural; then you should clearly tell EF whether to macrate the table data / From:
[Table ("Price")] Public Sector Price {...}
Comments
Post a Comment