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