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的一个问题.
有人有类似的问题吗?
不确定是否截断了您的示例,但如果您使用多个参数,则可能是问题所在: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.
以上是内存溢出为你收集整理的使用odp.net的Oracle实体框架不在linq查询中获取参数全部内容,希望文章能够帮你解决使用odp.net的Oracle实体框架不在linq查询中获取参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)