Reputation: 3328
I am trying to update only one column which is EntityType. But i am getting this error while making the join and update statement.
Only primitive types or enumeration types are supported in this context.
var entityCodesRepo = _context.EntityCodes.ToList();
var qualifiedRecs = await (from px in searchQuery
join ecx in entityCodesRepo on px.EntityCodeID equals ecx.EntityCodeID
select new IDMS_Partner()
{
EntityType = ecx.DisplayLabel
}
).ToListAsync();
Please suggest where am i making the mistake.
[Table("IDMS_Partner")]
public partial class IDMS_Partner
{
[Key]
public int PID { get; set; }
public int EntityCodeID { get; set; }
public string EntityType { get; set; }
}
Upvotes: 1
Views: 152
Reputation: 2898
You can't join IQueryable
with IEnumerable
in Linq-to-Entities so you should not materialize EntityCodes
using ToList
before joining with searchQuery
. The second thing is that in EF 6 you can't really create partial entities inside a query (this is not true in EF Core though) so if IDMS_Partner
belongs to the context you will get an error so either use an anonymous type or some DTO class. So finally your query should look like this:
var entityCodesRepo = _context.EntityCodes;
var qualifiedRecs = await (from px in searchQuery
join ecx in entityCodesRepo on px.EntityCodeID equals ecx.EntityCodeID
select new IDMS_PartnerDTO //it doesn't belong to context
{
EntityType = ecx.DisplayLabel
}).ToListAsync();
Upvotes: 1