简体   繁体   English

如何在现有的远程数据库中添加表并将其链接到Entity Framework模型?

[英]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. 我们正在使用带有Entity Framework的远程数据库,但我不知道用于创建数据库的方法。 What I would like to do is add a class to the project, add the class to DbSet an create the table automatically. 我想做的是将一个类添加到项目中,将该类添加到DbSet中,然后自动创建表。 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. 现在,当我在nuget中使用update-database时,我得到“此数据库未启用迁移”及其真实信息,没有配置文件或任何建议使用它的创建方法。

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. 简而言之:我想在远程数据库中添加一个新表,该表将由Entity Framework提取并为​​我生成一个类。 There is also NO .edmx file that can update the model. 也没有可以更新模型的.edmx文件。 How was this done then... (?) 那是怎么做到的...(?)

I am a new to Entity Framework, so apologies it some of this does not make sense. 我是Entity Framework的新手,因此对此表示歉意,其中有些道理没有意义。 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. 我以前曾经这样做,但是问题是我的DbSet名称为复数,而数据库为单数。 For instance: Products was the DbSet name and Product table in database. 例如:Products是数据库中的DbSet名称和Product表。 The actual class is still singular. 实际的类仍然是单数。

Thanks again! 再次感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将基本表添加到使用Entity Framework创建TPH模型的现有实体? - How can I add a base table to an existing entity creating TPH model using Entity Framework? 使用Entity Framework将模型映射到现有数据库表 - Map model to existing database table using Entity Framework 实体框架-添加现有数据库 - Entity Framework - Add Existing Database 将列/属性添加到现有的实体框架模型 - Add columns/properties to existing Entity Framework Model 实体框架6从现有表创建模型 - Entity Framework 6 Create model from existing table 将不带键的现有表添加到实体框架模型 - Adding an existing table with no Key to an Entity Framework model 从Entity Framework中的现有表创建模型 - Creating model from existing table in Entity Framework 使用实体框架向现有数据库添加或更新数据 - Add or update data to existing database with entity framework 使用实体框架在创建新实体时向数据库中的现有表添加新记录 - Add a new record to existing table in the database on a new entity creation using Entity Framework 实体框架:如何在数据库中的同一表的模型中具有多个实体? - Entity Framework: How to have several entites in model for same table in database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM