LINQ, Unable to create a constant value of type XXX. Only primitive types or enumeration types are supported in this con
Tag : chash , By : user93312
Date : March 29 2020, 07:55 AM
Any of those help In my application I have Lecturers and they have list of Courses they can teach and when I'm deleting a course I want to remove connection to lecturers. Here's the code: , You can't use Contains with non-primitive values. Do Where(l => l.Courses.Select(c => c.CourseId).Contains(courseId)
|
Unable to create a constant value of type ''YYY". Only primitive types or enumeration types are supported in this c
Date : March 29 2020, 07:55 AM
I hope this helps you . I have an entity Person and a view model that contains a collection of persons. , You can do like this , var Ids=vm.PersonCollection.Select(y => y.Id).ToArray();
ICollection<Person> prsn =
new PersonRepository().GetAll().Where(x => Ids.Contains(x.Id)).ToList();
|
Unable to create a constant value of type 'X.Models.Game'. Only primitive types or enumeration types are supported in th
Date : March 29 2020, 07:55 AM
To fix the issue you can do Not sure if it will work, but try instru.Games.Any(q => q.Id == selectedGame.Id) instead of instru.Games.Contains(selectedGame). Hope this helps!
|
Asp.Net - Unable to create a constant value of type. Only primitive types or enumeration types are supported in this con
Tag : chash , By : Jesenko Mehmedbasic
Date : March 29 2020, 07:55 AM
this will help I suspect that the problem is that you are using a complex type in your query for comparison f.UpFile.Equals(upFile) Why don't you try comparing by a primitive type such as the upFile id for example? var fields = from f in db2.Fields
where f.UpFile.ID == upFile.ID
select f;
ViewBag.Fields = fields.ToList();
|
Unable to create a constant value of type 'AddressModel'. Only primitive types or enumeration types are supported in thi
Date : March 29 2020, 07:55 AM
I wish this help you That is because childContactAddress object (and also taxReceiptChargesModelList) is already in memory and when you try to assign a complex object in the projection of your second query, the Linq provider can't translated that object to SQL. One option can be call AsEnumerable extension method: return unitOfWork.LegacyTaxReceiptStore.GetQuery()
.Where(ltr => ltr.LegacyTaxReceiptId ==ltrm.LegacyTaxReceiptId)
.AsEnumerable()
.Select(c => new TaxReceiptsWithChargesModel()
{
LegacyTaxReceiptId = ltrm.LegacyTaxReceiptId,
ChildContactId = ltrm.ChildContactId,
ChildContact = ltrm.ChildContact,
EmailAddress = ltrm.EmailAddress,
ChildId = ltrm.ChildId,
ChildName = ltrm.ChildName,
ChargesTotal = ltrm.ChargesTotal,
TaxReceiptAmount = ltrm.TaxReceiptAmount.Value,
TaxReceiptYear = ltrm.TaxReceiptYear,
Address = childContactAddress,
ReceiptNumber = $"{ltrm.TaxReceiptYear}-{ltrm.LegacyTaxReceiptId.ToString().PadLeft(6, '0')}",
Charges = taxReceiptChargesModelList,
}).FirstOrDefault();
var result=unitOfWork.LegacyTaxReceiptStore.GetQuery()
.FirstOrDefault(ltr => ltr.LegacyTaxReceiptId ==ltrm.LegacyTaxReceiptId);
return new TaxReceiptsWithChargesModel()
{
LegacyTaxReceiptId = result.LegacyTaxReceiptId,
ChildContactId = result.ChildContactId,
ChildContact = result.ChildContact,
EmailAddress = result.EmailAddress,
ChildId = result.ChildId,
ChildName = result.ChildName,
ChargesTotal = result.ChargesTotal,
TaxReceiptAmount = result.TaxReceiptAmount.Value,
TaxReceiptYear = result.TaxReceiptYear,
Address = childContactAddress,
ReceiptNumber = $"{result.TaxReceiptYear}-{result.LegacyTaxReceiptId.ToString().PadLeft(6, '0')}",
Charges = taxReceiptChargesModelList,
};
|