使用odp.net的Oracle实体框架不在linq查询中获取参数

前端之家收集整理的这篇文章主要介绍了使用odp.net的Oracle实体框架不在linq查询中获取参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用odp.net在Oracle中使用EntityFramework.参数化的SQL查询不起作用.
var orderCode = "XYZ";
var set = ctx.Database.sqlQuery<Order>(
    "Select * from dwh.Orders where OrderCode = '{0}'",orderCode
);

(要么)

var set1 = ctx.Database.sqlQuery<Order>(
    "Select * from dwh.Orders where OrderCode = ':param'",new OracleParameter("param",orderCode)
);

Console.WriteLine(set.Count() + "," + set1.Count()); //Gives 0,0

但是,如果我有硬编码值,它就可以了.

var set = ctx.Database.sqlQuery<Order>(
    "Select * from dwh.Orders where OrderCode = 'XYZ'",orderCode
);

有人知道为什么吗?我在该视图中有150列.那是问题吗?

更新:
使用Oracle参数的查询有效.问题是我在:param变量周围有单引号.

话虽如此,带有“{0}”的热门查询不起作用.此外,以下linq查询不起作用.

var set = ctx.Orders.Where(a => a.OrderCode == orderCode); // Gets zero results.

当我对值进行硬编码时,它可以正常工作并获取结果.

var set = ctx.Orders.Where(a => a.OrderCode == "XYZ"); // Gets the results correctly.

更新2:
查询使用Devart的dotconnect驱动程序.看起来这是odp.net的一个问题.

有人有类似的问题吗?

@H_301_32@ 不确定是否截断了您的示例,但如果您使用多个参数,则可能是问题所在:

Parameterized query in Oracle trouble

Although I can’t see anything wrong with your example,I wonder if you’re being hit by the old BindByName problem. By default,ODP.NET binds parameters to the query in the order in which they are added to the collection,rather than based on their name as you’d like. Try setting BindByName to true on your OracleCommand object and see if that fixes the problem.

原文链接:/oracle/205163.html

猜你在找的Oracle相关文章