I have a project that used to use DBML as the ORM for getting data out of our database. We are in the process of replacing this DBML with Entity Framework Core 2.2.6 (unfortunately the most recent version we can use as we must support old .Net 4 framework code).
I have a block of LINQ that worked using the old DBML code but does not work in the EF Core framework 2.2.6. The error message I'm getting is:
No mapping to a relational type can be found for the CLR type 'Expression[]'.
List<datadictproperty> dprop = (from dd in dBConnection.datadictproperties
where
dd.entityid == ent.id &&
dd.clientid == clientid &&
((((dd.suppress <= emp.seclevel &&
dd.suppress != Constants.g_everyone_seclevel) ||
dd.suppress == null)) || ignoreSecLevel) ||
(!
(from d in dBConnection.datadictproperties
where
d.entityid == ent.id &&
d.clientid == clientid &&
d.name == dd.name
select new
{
d.name
}).Contains(new { dd.name }) &&
dd.entityid == ent.id &&
dd.clientid == null &&
((((dd.suppress <= emp.seclevel &&
dd.suppress != Constants.g_everyone_seclevel) ||
dd.suppress == null)) || ignoreSecLevel))
orderby
dd.name
select dd).ToList();
One thing I can add which may make this easier is that the following statement should return zero or one row, so FirstOrDefault() may work. At the moment it is returning an Anonymous List<T> type.
(from d in dBConnection.datadictproperties where
d.entityid == ent.id &&
d.clientid == clientid &&
d.name == dd.name
select new
{
d.name
})
The piece of the statement that I think does not work is the following:
d.name == dd.name
select new
{
d.name
}).Contains(new { dd.name })
My issue is that I can't figure out how to change this code to correctly get the same data using EF Core 2.2.6 technology.
Is there anyone who could give me some ideas as to how I can change this code to produce the same data and thereby not generate a runtime error mentioned above?
Any help would be greatly appreciated :)
I have figured out how to fix this code. The end result was to use the following code:
It seems that changing it to the following it worked. I assume because it is not an anonymous type once being selected.