How do you write a parameterized where-in raw sql query in Entity Framework

后端 未结 3 1692
忘掉有多难
忘掉有多难 2020-12-15 05:30

How do you write a parameterized where-in raw sql query in Entity Framework? I\'ve tried the following:

string dateQueryString = String.Join(\",\", chartMode         


        
3条回答
  •  北海茫月
    2020-12-15 06:16

    I'd write a stored proc instead which accepts your parameters, then add the proc to your edmx.

    Then, in the edmx -> Model Browser -> Function Imports -> ... change the return type of the stored proc to SPCDataSeqCntInfo.

    Entity framework will then take care of passing in your parameters.

    e.g.

    public static List GetSPCDataSeqCntInfo(DateTime dateParam, string lineCode, int modelNum, int equipmentNumber, int lotNum)
    {
        using (var db = new NameOfMyEntites())
        {
            return db.sp_GetSPCDataSeqCntInfo(dateParam, lineCode, modelNum, equipmentNumber, lotNum).ToList();
        }
    }
    

提交回复
热议问题