我已经在我的项目中将linq应用于sql并且花了很多时间所以我进行了搜索以使其快速进行搜索并从here
获取参考我的.cs代码是
public static Func<DataClassesDataContext, int, IQueryable<editor_j_inf>>
editordetail1 = CompiledQuery.Compile((DataClassesDataContext db, int a) =>
from p1 in db.editor_j_infs
where p1.ed_journal_id == a
orderby p1.editor_id descending
select p1); //Its my precompile process
public void editordetail()
{
DataClassesDataContext db = new DataClassesDataContext();
var rr = editordetail1(db,Convert.ToInt32(Server.HtmlEncode(Request.Cookies["j_id"].Value)));
}
并且它工作正常,但如果我想在编译查询中传递2或3个值,我该怎么办? 假设我的选择查询是
public void editordetail()
{
DataClassesDataContext db = new DataClassesDataContext();
var rr = from p in db.tbl_desc_indexes
where p.ed_journal_id == 1 && p.j_id==2 && p.j_id1==3
select p
}
我应该如何为此编译查询?
答案 0 :(得分:0)
public static Func<DataClassesDataContext, int, int, int, IQueryable<tbl_desc_index>>
editordetail1 =
CompiledQuery.Compile((DataClassesDataContext db, int a, int b, int c) =>
from p in db.tbl_desc_indexes
where p1.ed_journal_id == a && p.j_id == b && p.j_id1 == c
select p);
话虽如此,您是否已分析过数据库查询?也许你需要改进索引?或者您可能需要重新设计应用程序,以便它需要执行更少的查询?