make compiled queries while sending 2 int

2019-09-16 03:34发布

I have applied linq to sql in my project and it's taking a lot of time so I made a search to make it speedy and i have searched and took a reference from here

And my .cs code is

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

}

and its working fine but what should i do if i wanna pass 2 or 3 values in compiled queries suppose my select queries is

 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

}

How should i make compiled queries for this ??

1条回答
beautiful°
2楼-- · 2019-09-16 04:01
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);

That being said, have you profiled your database queries? Maybe you need to improve your indexes? Or maybe you need to redesign the application, such that it needs to do less queries?

查看更多
登录 后发表回答