I have a number of different data sources that I need to query and have been able to do confine all my queries to very simple expressions with no more than 2 conditions. An example of typical complexity of my lamba Expressions is:

我有许多不同的数据源需要查询,并且能够将我的所有查询限制在非常简单的表达式中,条件不超过2个。我的lamba表达式的典型复杂性的一个例子是:

b => b.user == "joe" && b.domain == "bloggs.com"

On my non-SQL data sources I'm ok as I can convert them to object lists and use a LINQ query such as:

在我的非SQL数据源上我很好,因为我可以将它们转换为对象列表并使用LINQ查询,例如:

public override T Get(List<T> assets, Expression<Func<T, bool>> whereClause)
{
    return assets.Where(a => whereClause.Compile()(a)).FirstOrDefault();
}

My problem is when I need to query a relational database - I'm only really concerned with Postgresql and MySQL - I've been struggling a bit. I've got nHibernate to Linq "working" but have had some issues where it stalls and stops accessing the database or can't close connections, typical sort of things to expect from something in beta so I'm not complaining.

我的问题是当我需要查询关系数据库时 - 我只关心Postgresql和MySQL - 我一直在苦苦挣扎。我有nHibernate到Linq“工作”,但有一些问题,它停止和停止访问数据库或无法关闭连接,典型的事情期待从beta的东西,所以我不抱怨。

Because my queries are so simple and I am happy to build the SQL myself I'd like to know if there is a relatively painless way to turn my Expression's into SQL where clauses?

因为我的查询非常简单,我很乐意自己构建SQL,我想知道是否有一种相对无痛的方式将我的Expression转换为SQL where子句?

I've had a quick search around and found some samples and of course there are already some Linq-to-SQL engines so I know it can be done. The question is whether it's something I can whip up in a day or less of effort? That's what I'd estimate it would take me to find a compatible Linq-to-SQL library and load test it assuming it works out ok. I do have big performance considerations so raw SQL is preferrable for me instead of running through an ORM.

我已经快速搜索并找到了一些样本,当然已经有一些Linq-to-SQL引擎所以我知道它可以完成。问题是,我是否可以在一天或更少的努力中鞭打它?这就是我估计它会让我找到一个兼容的Linq-to-SQL库并加载测试它假设它运行正常。我确实有很大的性能考虑因素,因此原始SQL对我而言更适合而不是通过ORM运行。

2 个解决方案

#1


Writing a LINQ provider can be very difficult. I would suggest looking into these links:

编写LINQ提供程序可能非常困难。我建议调查这些链接:

Linq Provider for MySql, Postgres, Oracle (This is open-source)
Writing custom LINQ provider

Linq Provider for MySql,Postgres,Oracle(这是开源的)编写自定义LINQ提供程序

更多相关文章

  1. MySQL基础入门学习【7】查询表达式解析 SELECT
  2. Web开发实战学习(涉及EL表达式,JSTL,数据库)
  3. JNDI学习总结(一)——JNDI数据源的配置
  4. java配置使用数据源
  5. Java常量表达式相关的编译优化代码
  6. java8中lambda表达式
  7. java 正则表达式查找某段字符串中所有小写字母开头的单词并统计
  8. Java正则表达式提取字符
  9. 如何在JDBC数据源级别限制从Oracle返回的行数?

随机推荐

  1. cocos2d-x环境搭建 for eclipse
  2. Android 原生开发、H5、React-Native开发
  3. [实战示例] 带您深入探讨 Android 传感器
  4. Android一个textview显示多段文本不同颜
  5. Android下获取Root权限和设置目录属性
  6. Android开发小知识文章目录
  7. Android(安卓)App状态栏动态显示隐藏
  8. Android UI 之 onTouchEvent, onClick及o
  9. Android Layout布局文件里的android:layo
  10. 哪些年遇到过的Andriod问题(5)This text