如何在Entity Framework 4.1中使用IsNull映射具有列数据类型int的表 [英] How to map the Table having column data type int with IsNull in Entity Framework 4.1
问题描述
大家好,
我在Entity Framework 4.1中遇到了表映射的一个问题.
我有一个表名称Promotion,具有列intDeletedBy和datDeletedOn
而且我只想从数据库中获取未删除的记录
但是当我将带有实体框架的表映射为intDeletedBy列或datDeletedOn
我在条件标签上收到一条错误消息
Hello All,
I am facing one issue with Table Mapping in Entity Framework 4.1.
I have a table name Promotion having column intDeletedBy and datDeletedOn
and i want to fetch only those records from DB which are not deleted
but when i map the table with entity frame work for the column intDeletedBy or datDeletedOn
i am getting an error message on the condition tag
错误3032:映射片段的问题从第261行开始:条件成员"CMS_Promotion.datDeletedOn"的条件不是'' IsNull = False''已映射.删除CMS_Promotion.datDeletedOn上的条件,或将其从映射中删除.
Error 3032: Problem in mapping fragments starting at line 261:Condition member ''CMS_Promotion.datDeletedOn'' with a condition other than ''IsNull=False'' is mapped. Either remove the condition on CMS_Promotion.datDeletedOn or remove it from the mapping.
我的xml代码在C-S映射内容中
my xml code is in C-S mapping content
<EntitySetMapping Name="Promotions">
<EntityTypeMapping TypeName="Lorenz_dataModel.Promotion">
<MappingFragment StoreEntitySet="CMS_Promotion">
<ScalarProperty Name="PromotionId" ColumnName="autPromotionId" />
<ScalarProperty Name="Name" ColumnName="vchName" />
<ScalarProperty Name="Description" ColumnName="vchDescription" />
<ScalarProperty Name="ValidFrom" ColumnName="datValidFrom" />
<ScalarProperty Name="ValidTo" ColumnName="datValidTo" />
<ScalarProperty Name="CreatedBy" ColumnName="intCreatedBy" />
<ScalarProperty Name="CreatedOn" ColumnName="datCreatedOn" />
<ScalarProperty Name="ModifiedBy" ColumnName="intModifiedBy" />
<ScalarProperty Name="ModifiedOn" ColumnName="datModifiedOn" />
<ScalarProperty Name="DeletedBy" ColumnName="intDeletedBy" />
<ScalarProperty Name="DeletedOn" ColumnName="datDeletedOn" />
<Condition ColumnName="datDeletedOn" IsNull="true"/>
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
请建议我如何克服这个问题.
我不想更改数据库表的数据类型
等待回复
谢谢
pls suggest me how can i overcome from this issue.
I dont want to change the datatype of my db table
waiting for reply
Thanks
推荐答案
您可以为期望为空的列声明数据类型为可空
请参考此参考 [
you can declare datatype as nullable for columns you expect to be null
please refer this as reference[^] for same.
这篇关于如何在Entity Framework 4.1中使用IsNull映射具有列数据类型int的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!