This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hey guys, Today we tried to migrate some of our projects to LS 3. We use filters in our repositories to generate the linq code to get data from the database. This worked fine in 2.2 but now i'm getting:
*** Failures ***
Here is what we do: I'm trying to execute this statement (which will return 1 record): var assetType = _uow.Current.AssetTypes.FirstOrDefault(); The extension methods in this code look like this: public static IQueryable<Device> ByAssetType(this IQueryable<Device> devices, AssetType assetType) Device and DeviceType are normal LS Entities AssetType Inherits from an Entity called Code with a discriminator CodeType = "asset_type". The weird thing is that when i call my code with a ToList() it does return a list with 1 record and does not crash. The query which is executed when I do a ToList looks like this: BEGIN This query looks a bit weird (it is joining all the tables but is also using an EXISTS to filter) but it works. We also have an many to many link between the Device table and the MP_STATIC table (linked through a table called MP_STATIC_DEVICE). the Device -> MP_STATIC_DEVICE is an eager load. The where statement of the first query also seems to be included in the eager load query: SELECT mp_static_device.MP_STATIC_DEVICE_ID, mp_static_device.mp_static_id, mp_static_device.device_id, mp_static_device.code_metering_type_id, mp_static_device.Modified, mp_static_device.Modifier, mp_static_device.VALID_FROM, mp_static_device.VALID_TILL FROM mp_static_device WHERE EXISTS ( SELECT t0.* FROM Device t0 WHERE t0.DEVICE_ID = mp_static_device.device_id AND (t0.DEVICE_CODE = '00923133' AND EXISTS ( SELECT t1.* FROM DEVICE_TYPE t1 WHERE t1.DEVICE_TYPE_ID = t0.device_type_id AND EXISTS ( SELECT t2.* FROM CODE t2 WHERE t2.CODE_ID = t1.code_type_id AND t2.CODE = 'INDMTR' ) )) ); I hope you can explain to me why we are getting an NullReferenceException. it currently blocks our migration to LS 3. Regards, Rolf |
|
|
I also tried to rewrite the code to make it use joins (my hope was it will eliminate the exist statements, and it did), but the where statement of the first query still seems to be included in the query of the eager load: For this test I was doing this: var device = (from d in _uowElectricity.Current.Devices which executed the following queries: BEGIN Now I get an exception on the second query because t2.Code does not exist, which true because there is no t2 in that query. Maybe this will help you finding out what the problem is. For our migration dont want to change too many code switching from LS 2 to LS 3. so preferably I would want the statement of the first post to work the same as LS 2.2. Could it be that LS is trying to SingleOrDefault the EagerLoad as well for instance? Regards Rolf |
|
|
Hi Rolf, I would be keen to have a peek at both of these issues - Are you able to send through a small repro of this behavior? Unfortunately the stack trace isnt specific enough to allow us to track down this issue and the query generation is somewhat dependant on the model so if you can send through a small data set and the model then that would help us progress this. You can either attach the file to the forum post, or if it contains any sensitive information or you would rather send it privately please email it through to jeremy@mindscape.co.nz and I can have a look at this.
Jeremy |
|
|
Hi Jeremy, I downloaded the nightly (LightSpeed30Professional-20100112.msi) and both issues in this thread are have been resolved. Thanks! The new generated queries look great. Regards Rolf
|
|