linq無法創建“匿名類型”類型的常量值;此上下文僅支持基元類型或枚舉類型


問題:linq無法創建“匿名類型”類型的常量值;此上下文僅支持基元類型或枚舉類型

來源:

            var data = from r in db.ActUserDrawRecord_J
                       join g in db.ActGift_J on r.GiftID equals g.GiftID
                       join u in db.UserInfo on r.UserID equals u.UserID
                       join c in db.ActConfig_J on r.ActID equals c.ActID
                       where string.IsNullOrEmpty(phoneCode) ? true : u.PhoneCode == phoneCode
                       && string.IsNullOrEmpty(stationCode) ? true : r.EStationCode == stationCode
                       && string.IsNullOrEmpty(giftName) ? true : g.GiftName == giftName
                       && r.ActID == actId &&r.State==1
                       orderby r.UseTime descending
                       select new
                       {
                           PhoneCode = u.PhoneCode,
                           GiftName = g.GiftName,
                           UseTime = r.UseTime,
                           EStationCode = r.EStationCode,
                           EAccountType = r.EAccountType,
                           Ephone = r.EPhone,
                           EName = r.EName
                       };

解決方案:

將各個查詢條件加()

            var data = from r in db.ActUserDrawRecord_J
                       join g in db.ActGift_J on r.GiftID equals g.GiftID
                       join u in db.UserInfo on r.UserID equals u.UserID
                       join c in db.ActConfig_J on r.ActID equals c.ActID
                       where (string.IsNullOrEmpty(phoneCode) ? true : u.PhoneCode == phoneCode)
                       && (string.IsNullOrEmpty(stationCode) ? true : r.EStationCode == stationCode)
                       && (string.IsNullOrEmpty(giftName) ? true : g.GiftName == giftName)
                       && (r.ActID == actId) &&(r.State==1)
                       orderby r.UseTime descending
                       select new
                       {
                           PhoneCode = u.PhoneCode,
                           GiftName = g.GiftName,
                           UseTime = r.UseTime,
                           EStationCode = r.EStationCode,
                           EAccountType = r.EAccountType,
                           Ephone = r.EPhone,
                           EName = r.EName
                       };

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM