number 16 6 oracle,Oracle和Entity Framework 6:Int32以数字形式返回(Oracle and Entity Framework 6: Int32 retur...

Oracle和Entity Framework 6:Int32以数字形式返回(Oracle and Entity Framework 6: Int32 returned as number)

伙计们,

我在EF6中针对Oracle DB有一个数据库优先项目,我在模型中指定某些列应该是Int32s。 但是,当返回Web API有效负载时,这些属性将作为Numbers返回,例如58.0,3.0,486.0等等......这使得整个JSONDeserializer在整个过程中都会被抛出。

我认为我应该能够在EF中改变它的映射,但是目前究竟是什么让我不知所措。 任何帮助将非常感激!

编辑澄清:

查看.edmx,属性显示应该是整数:

在Oracle方面,我可以确认它们是Number。

至于为什么Web API包含在这个OP中:我只是想提供一些关于如何返回请求的上下文。 我没有使用DTO,而是直接返回模型。

很高兴提供更多信息(我一到笔记本电脑)。

ñ

Folks,

I have a database-first project in EF6 against an Oracle DB, and I have specified in the model that certain columns should be Int32s. However, when the Web API payload is returned, those properties are returned as Numbers, such as 58.0, 3.0, 486.0 and so on... which makes thr entire JSONDeserializer throw up royally, of course.

I presume I should be able to change the mapping within EF for it, but how exactly is eluding me at the moment. Any help would be much appreciated!

Editing for clarification:

Looking at the .edmx, the properties show the should-be integers as:

On the Oracle side, I can confirm that they are Number.

As to why Web API is included in this OP: I'm just trying to provide some context as to how the requests are being returned. I'm not using a DTO but rather returning the model directly.

Happy to provide more info (as soon as I get to a laptop).

N

原文:https://stackoverflow.com/questions/30315299

更新时间:2019-11-12 12:24

最满意答案

好吧,对于可能遇到同样困难的其他人来说,看起来这样可行。

如果您正在使用Oracle的托管数据访问库,请将以下内容添加到您的app / web.config:

或根据自己的口味调整。 但请注意,您可能还必须映射Int64(即使我不相信我的数据库中有任何可以量化的内容,我有时会得到初始化程序异常。

您可能必须从.edmx文件中删除模型并重新添加。

但这将解决您的问题,并且您的JSON将不再以小数形式返回。

希望有所帮助! (并保持优雅,Oracle ...;))

OK, looks like this will work, for anyone else who may be having the same difficulties.

If you're using the managed data access libraries from Oracle, add the following to your app/web.config:

Or adjust to your own taste. Do note, however, that you might have to map Int64 as well (even though I don't believe I have anything in my DB that would quantify as such, I would sometimes get an initializer exception.

You may have to delete your model from your .edmx file and re-add it.

But that will fix your issues, and your JSON will not be returned as decimals anymore.

Hope that helps! (And keep it classy, Oracle... ;) )

2015-05-19

相关问答

我现在无法测试它,但它可能是索引器,试试这个: foreach (var treauserHunt in treasureHunts)

{

treasureHunt.Leaderboard = dbContext.Leaderboard.Where(leaderboard =>

leaderboard.TreasureHuntId == treasureHunt.TreasureHuntId).ToList();

}

我不确定这是否是问题,但我记得在LINQ查询中有一些

...

DevArt的OraDirect提供商现在支持实体框架。 见http://devart.com/news/2008/directs475.html DevArt's OraDirect provider now supports entity framework. See http://devart.com/news/2008/directs475.html

好吧,对于可能遇到同样困难的其他人来说,看起来这样可行。 如果您正在使用Oracle的托管数据访问库,请将以下内容添加到您的app / web.config:

...

您需要将int存储在变量中,以便EntityFramework不会将整个数组拖入其范围。 var myInt = myInts[0];

var query = (from d in db.MYTABLE

where d.RELID.Equals(myInt)

select d.ID).Distinct();

List urunidleri = query.ToList();

You need to store your int

...

在C#中这不是非法吗? 如果“int”仅为“Int32”的别名,则无法使用错误CS0523进行编译。 编译器有没有魔法? 是; 在编译器中故意压制该错误。 如果所讨论的类型是内置类型,循环检查器将被完全跳过。 通常这种事情是非法的: struct S { S s; int i; }

在这种情况下,S的大小是未定义的,因为无论S的大小如何,它必须等于本身加上int的大小。 没有这样的大小。 struct S { S s; }

在这种情况下,我们没有可以推断出S的大小的信息。 struct Int

...

解决了它,添加到web.config:

使用*.edmx文件重新创建模型并... 现在Number(5)是Int32而不是Int16而N

...

ODAC 12c(或任何其他版本)仍不支持实体框架6。 支持的EF是4.5和5.第三方产品,例如Devart,似乎是目前唯一的选择。 我没有看到Oracle发布任何可能发布日期的声明。 Entity Framework 6 is still not supported by ODAC 12c (or any other version). Supported EFs are 4.5 and 5. Third party products, e.g. Devart, seems to be the

...

十进制类型的范围小于您尝试将其设置为的数字,因此错误。 Decimal类型值是它的精度,MS Reference文章声明它更好地用于财务计算。 https://docs.microsoft.com/en-us/dotnet/articles/csharp/language-reference/keywords/decimal 对于你的示例数据,我倾向于使用double,它的范围很大但不如十进制类型精确 https://docs.microsoft.com/en-us/dotnet/articles

...

首先,我强烈建议不要将列转换为int,否则会丢失列上的索引。 您宁愿将int转换为字符串。 但是,这是如何修复您的代码。 首先签署贡献者许可协议 。 然后你派生Entity Framework git repo 。 编写一个新的MethodCallTranslator.CallTranslator ,它将采用Convert.ToInt32(string)并将其替换为(int) string 。 在MethodCallTranslator注册新的MethodCallTranslator 。 为您的测

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值