After lots of time of investigation, I could not manage successfully a multiple INCLUDE query to eager load a mother class including its 2 linked classes.
var query = _context.MotherClass
.Include(o => o.LinkedClass1)
.Include(o => o.LinkedClass2);
var result = query.ToList();
In fact it fails on data mismatch issue on the object of type LinkedClass2.
The ORM detect a STRING whereas the Class Property as well as the DB field are both DOUBLE.
Why?
It seems it is because the SQL generated is split in 2 parts joined with a UNION ALL and in the FIRST part of the request the field from the LinkedClass2 table are set to (null).
Indeed, the engine is unable to detect a field type if in the FIRST part of the UNION ALL, the field value is NULL and NOT CASTED explicitly.
We have:
SELECT (null) FROM ...
UNION ALL
SELECT 123.45 FROM ...
Note that, as a SQL query result, some strange (Chinese?) characters are returned (the table is nevertheless displayed properly while opened MS Access) => data mismatch
In standard EF, we would have rather (working):
SELECT CAST(null as Double) FROM ...
UNION ALL
SELECT 123.45 FROM ...
Note that the reverse query below allows the ORM to detect the proper field type (Double) if the NULL is on the SECOND part
SELECT 123.45 FROM ...
UNION ALL
SELECT (null) FROM ...
I would recommend to force the CAST of any NULL value in JET SQL Generation mechanism.
From Keops31
After lots of time of investigation, I could not manage successfully a multiple INCLUDE query to eager load a mother class including its 2 linked classes.
In fact it fails on data mismatch issue on the object of type LinkedClass2. The ORM detect a STRING whereas the Class Property as well as the DB field are both DOUBLE.
Why? It seems it is because the SQL generated is split in 2 parts joined with a UNION ALL and in the FIRST part of the request the field from the LinkedClass2 table are set to (null). Indeed, the engine is unable to detect a field type if in the FIRST part of the UNION ALL, the field value is NULL and NOT CASTED explicitly.
We have:
Note that, as a SQL query result, some strange (Chinese?) characters are returned (the table is nevertheless displayed properly while opened MS Access) => data mismatch
In standard EF, we would have rather (working):
Note that the reverse query below allows the ORM to detect the proper field type (Double) if the NULL is on the SECOND part
I would recommend to force the CAST of any NULL value in JET SQL Generation mechanism.