简体   繁体   English

实体框架 6.0 SQL 优先与没有 .edmx 的数据库同步?

[英]Entity Framework 6.0 SQL-first synch with database without .edmx?

I have a database with some tables for school related project and I have a model with EF 6.0 SQL-first approach.我有一个数据库,其中包含一些用于学校相关项目的表,并且我有一个采用 EF 6.0 SQL-first 方法的模型。 I need to update the database with a new table & update an existing table with a new column.我需要用新表更新数据库并用新列更新现有表。 The twist is: I don't have any *.edmx file.扭曲是:我没有任何 *.edmx 文件。 How can I update the model without it?没有它我如何更新模型? If it is impossible, then how can I generate *.edmx without interrupting the existing model?如果不可能,那么如何在不中断现有模型的情况下生成 *.edmx?

Entities are essentially POCOs, so you really just need to update your schema and update the entity classes to match.实体本质上是 POCO,因此您实际上只需要更新架构并更新实体类以匹配。 For new entities if the project is not using an edmx then it should either be using classes extending EntityTypeConfiguration or setting things up with the modelBuilder on the OnModelCreating event in the DbContext.对于新实体,如果项目不使用 edmx,那么它应该使用扩展EntityTypeConfiguration类,或者在 DbContext 中的OnModelCreating事件上使用模型构建器进行设置。

EF can resolve most general mappings using convention, so adding a column to a table usually just means adding the property to the entity. EF 可以使用约定解析大多数通用映射,因此向表中添加列通常仅意味着向实体添加属性。 Mapping only comes into play when you want to change a columns naming, handle type casting differences, or use identity/computed columns.映射仅在您想要更改列命名、处理类型转换差异或使用标识/计算列时才起作用。 For new entities it can also use convention, but commonly there would be config used for the Table name, PK name, and things like Identity columns, plus navigation properties for related entities.对于新实体,它也可以使用约定,但通常会有用于表名称、PK 名称和身份列之类的配置,以及相关实体的导航属性。

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

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