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
|
Hi. I'm new to LightSpeed and have a question about how to query a data model. I have two related tables: patient cases and the medical record template used for each case. I want to query for all cases and the name of the template used. How do I write a LINQ query for this information using LightSpeed? It seems like an every day task. Here's what I currently have. Visual Studio is warning me the reference to the template table is "Access to disposed closure". using (LightSpeedModelUnitOfWork uow = context.CreateUnitOfWork()) { var cases = from d in uow.Datcases from t in uow.Usrtemplates select new {d.CasePatientFirstName, d.CasePatientLastName, d.CasePatientMiddleInitial};
Thanks for any help you can provide. I'm not seeing an example of this in the documentation... |
|
|
You're using ReSharper, right? I think that's where the error is coming from. I think you want to do a .ToList() instead of the cast. That executes the query before the using statement closes. More detail (including a possible glitch in ReSharper) here: http://devnet.jetbrains.net/thread/432978 |
|
|
You don't say where the 'Access to disposed closure' error occurs -- compiler error, runtime error or intellisense warning. It's not an error I've ever seen so I think chadw could well be right that this is a dubious Resharper error. Your LINQ query looks okay though you're not currently fetching the template name. You may however find that when you add this in, the query does not run efficiently the way it is written (there may be a N+1 problem loading the templates). Unless the entities are very large you may be better off just loading the cases as entities and eager-loading the templates; if the entities are large then you may need to do an explicit join (see http://www.mindscapehq.com/forums/thread/309973 for an example). However the list cast is not correct. The LINQ query returns an
and this needs to happen within the using statement so that all loading is complete before the unit of work is disposed. |
|
|
Yes, I'm using ReSharper. Thanks for the heads up on that. In short, I've implemented the suggested changes and am very happy with the results. Thanks to everyone for their help. |
|