Entity SQL 使用技巧

1.由Entity SQL获得标准SQL语句

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中执行查询语句:

 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方法执行!

 

你可能感兴趣的:(sql,sql,LINQ,LINQ,LINQ)