简体   繁体   中英

How to add table in existing remote database and link it to Entity Framework model?

I tried finding the answer to this question before posting, but couldn't.

We are using a remote database with Entity Framework and I do not know the approach it was used to create the database. What I would like to do is add a class to the project, add the class to DbSet an create the table automatically. Now, when I use update-database in nuget, i get "migrations not enabled for this database" and its true, there is no configuration file or anything that suggest the approach it was used for creation of this.

I wouldn't want to enable-migrations as I don't want to mess something up or loss data. (or should i?) The existing tables are working fine with the repository...

I created a table manually, added a class that maps the properties by name and hoped that entity framework will pick it up, but no luck.

Here it is in a nutshell: I want to add a new table in a remote database that will be picked up by Entity Framework an generate a class for me. There is also NO .edmx file that can update the model. How was this done then... (?)

I am a new to Entity Framework, so apologies it some of this does not make sense. I am happy to clarify.

Thanks,

Thank you for your responses. I managed to fix this by adding a new class into the repository, using code first approach and then I created a table manually in the database.. The Entity Framework pick it up somehow :)

I was doing this before, but the problem was that I had the DbSet name to plural and database to singular. For instance: Products was the DbSet name and Product table in database. The actual class is still singular.

Thanks again!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM