在发送 2 int 时进行编译查询



我已经在我的项目中将linq应用于sql,这需要很多时间,所以我进行了搜索以使其快速,我已经搜索并从这里获取了参考

我的.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
}

我应该如何为此进行编译查询?

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);

话虽如此,您是否分析了数据库查询?也许您需要改进索引?或者,也许您需要重新设计应用程序,以便它需要执行更少的查询?

最新更新