Entity Framework 映射了错误的数据类型
Entity Framework maps wrong datatype
我有一个数据库,其视图具有整数 FK。当我在 VS 中创建模型并查看图表时,视图的列为 string/varchar。我删除了 table 并重新添加了它,但它仍然使用字符串 属性.
创建实体
如果我 select 视图然后在 Properties 中将 Type 更改为 Int32 构建完成且没有错误,但在第一次调用 DB 上下文时中断说商店和模型不匹配。
DB table:
TariffKey : int
CompanyKey : int
ChargeTypeKey : int
ChargeTypeName : varchar(80)
Value : numeric
StartDate : datetime
EndDate : datetime
模型映射:
TariffKey : int (Int32)
CompanyKey : int (Int32)
ChargeTypeKey : varchar (String)
ChargeTypeName : varchar (String)
Value : numeric (Decimal)
StartDate : datetime (DateTime)
EndDate : datetime (DateTime)
模型的商店是问题所在 child。因此,即使我更改了图表中的数据类型,商店仍然有一个映射到该字段的 varchar。我遵循了 Update Model from Database does not see a type change
中 Mat 的回答
我有一个数据库,其视图具有整数 FK。当我在 VS 中创建模型并查看图表时,视图的列为 string/varchar。我删除了 table 并重新添加了它,但它仍然使用字符串 属性.
创建实体如果我 select 视图然后在 Properties 中将 Type 更改为 Int32 构建完成且没有错误,但在第一次调用 DB 上下文时中断说商店和模型不匹配。
DB table:
TariffKey : int
CompanyKey : int
ChargeTypeKey : int
ChargeTypeName : varchar(80)
Value : numeric
StartDate : datetime
EndDate : datetime
模型映射:
TariffKey : int (Int32)
CompanyKey : int (Int32)
ChargeTypeKey : varchar (String)
ChargeTypeName : varchar (String)
Value : numeric (Decimal)
StartDate : datetime (DateTime)
EndDate : datetime (DateTime)
模型的商店是问题所在 child。因此,即使我更改了图表中的数据类型,商店仍然有一个映射到该字段的 varchar。我遵循了 Update Model from Database does not see a type change
中 Mat 的回答