灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3102回复:0

[SQL Server]Entity SQL使用技巧

楼主#
更多 发布于:2012-12-13 15:08

Entity SQL使用技巧

1.由Entity SQL获得标准SQL语句
 www.atcpu.com  
Entity to Linq:

string sql=(this.ObjectContext.IrrLRoles.Where(d => d.rname.StartsWith("a")) as ObjectQuery).ToTraceString();

标准SQL:

SELECT
[Extent1].[rid] AS [rid],
[Extent1].[rname] AS [rname],
[Extent1].[state] AS [state],
[Extent1].[sysfuns] AS [sysfuns]
FROM [dbo].[IrrLRoles] AS [Extent1]
WHERE [Extent1].[rname] LIKE 'a%'

2.在Entity SQL中执行查询语句:  www.atcpu.com  

string ids = "1,2,3,4,5,6,7,8";

return this.ObjectContext.ExecuteStoreQuery<IrrlSysFun>("select * from IrrlSysFun as s where s.nodeid in ("+ids+")").AsQueryable();

通过ExecuteStoreQuery方法执行!

喜欢0 评分0
游客

返回顶部