使用实体框架将布尔属性映射到Oracle

编程入门 行业动态 更新时间:2024-10-28 17:16:42
本文介绍了使用实体框架将布尔属性映射到Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我首先需要使用实体模型将系统连接到oracle. 我有一个实体为"Entity1"的模型.顾名思义,"MyBool"是一个布尔型属性.

I need to connect a system to oracle using entity model first. I have a model with the entity "Entity1". "MyBool", as the name says, it's a boolean property.

我成功地从模型中生成了sql脚本,并在oracle数据库上运行了它.

I sucessfully generated the sql script from the model and run it on oracle database.

然后我有以下代码:

static void Main(string[] args) { Model1Container context = new Model1Container(); Entity1 entity = context.Entity1.FirstOrDefault(); }

此代码引发此异常:

指定的架构无效.错误:Model1.msl(8,12):错误2019: 指定的成员映射无效.方式 类型的成员'MyBool'的'Edm.Boolean [Nullable = False,DefaultValue =]' 'Model1.Entity1'与以下版本不兼容 'OracleEFProvider.number [Nullable = False,DefaultValue =,Precision = 1,Scale = 0]' 类型为"Model1.Store.Entity1"的成员"MyBool".

Schema specified is not valid. Errors: Model1.msl(8,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=False,DefaultValue=]' of member 'MyBool' in type 'Model1.Entity1' is not compatible with 'OracleEFProvider.number[Nullable=False,DefaultValue=,Precision=1,Scale=0]' of member 'MyBool' in type 'Model1.Store.Entity1'.

我读了很多主题,许多人说要补充:

I've read a lot of threads and many people said to add:

<oracle.dataaccess.client> <settings> <add name="bool" value="edmmapping number(1,0)" /> </settings> </oracle.dataaccess.client>

在配置文件中(在我的情况下,它是一个控制台应用程序,然后是app.config). 但这并没有改变任何东西.实际上,我可以在此参数上设置任何值,并且错误将完全相同.看来该参数没有被读取.

In config file (in my case it's a console app then app.config). But this didn't changed anything. Indeed I can set any value on this parameter and the error will be exactly the same. It looks like this parameter is not being read.

然后有人说:将Oracle.DataAccess DLL添加到项目中.我做了,结果是一样的.

Then some people said: Add Oracle.DataAccess DLL to the project. Which I did, and the results were the same.

我知道关于该主题的话题很多,但是它们中的任何一个都对我有所帮助,我不知道该怎么办. 请注意,我的实际应用程序模型已经在Sql Server上投入生产.

I know that are a lot of threads about this topic, but any of them helped me, and I don't know what else to do. Just to notice, my real application model is already on production on Sql Server.

推荐答案

经过一些研究,我发现为数据库number(1)映射到 bool类型具有自定义映射是完全可以的.缺点当然是2019年映射错误(或架构验证错误).如果要摆脱通常不会对解决方案造成任何问题的映射错误,请在构建过程中关闭模型验证,请将"Validate On Build"设置为false.

After doing some research I found that it's perfectly alright to have custom mapping for database number(1) mapping to bool type. The downside is of course the 2019 mapping error (or schema validation error). If you want to get rid of the mapping error which usually don't cause any problem to the solution build is to turn off model validation during build, set the "Validate On Build" to false.

更多推荐

使用实体框架将布尔属性映射到Oracle

本文发布于:2023-11-17 05:42:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609031.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔   实体   框架   属性   Oracle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!