简体   繁体   English

使用实体框架4执行包含复杂选择连接的自定义SQL

[英]Executing custom sql including complex select joins using entity framework 4

My application currently uses ado.net to access the database. 我的应用程序当前使用ado.net访问数据库。

It allows users to configure dashboards by passing custom sql. 它允许用户通过传递自定义sql来配置仪表板。 The custom sql includes joins on multiple tables and the columns of every table are included in the result. 定制sql包含多个表上的联接,并且每个表的列都包含在结果中。

We are migrating from ado.net to entity framework 4. 我们正在从ado.net迁移到实体框架4。

How do I execute the same queries using entity framework? 如何使用实体框架执行相同的查询?

Also other code in the application requires firing custom complex join queries on the database. 此外,应用程序中的其他代码也需要在数据库上触发自定义的复杂联接查询。 This is done by developers. 这是由开发人员完成的。

Yes you can use inline queries and even stored procedue in entityframework 是的,您可以在实体框架中使用内联查询甚至存储过程

see example for query http://msdn.microsoft.com/en-us/library/bb738451 请参阅查询示例http://msdn.microsoft.com/en-us/library/bb738451

see example for stored procedure http://msdn.microsoft.com/en-us/library/bb896334.aspx 请参见存储过程示例http://msdn.microsoft.com/zh-cn/library/bb896334.aspx

If you have dynamic queries you cannot execute them through EF. 如果您有动态查询,则无法通过EF执行它们。 EF works in strongly typed manner so it expects that you created the type with correct properties (with correct types) at design time (you can create the type at runtime as well but it requires you to create dynamic assembly, emit IL, etc.). EF以强类型化的方式工作,因此它期望您在设计时创建具有正确属性(具有正确类型)的类型(您也可以在运行时创建类型,但是它需要您创建动态程序集,发出IL等)。 。

Use your old approach for this type of queries. 对这种类型的查询使用旧的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM