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
|
I ran across this today and wanted to see what your thoughts were. I have a model where I want to select the only row that should be in the database with the Single() method. If there is more than one record this is supposed to throw an exception. With Lightspeed it appears that this is not the case. var setup = _uow.PayorSetups.Single(p => p.Id.PayorSetupSeqNo == payorSeq && p.Id.EffDate == effDate && p.Id.ExpDate == expDate); return setup.AsDto(); Should be the same as
var setup = _uow.PayorSetups.Where(p => p.Id.PayorSetupSeqNo == payorSeq && p.Id.EffDate == effDate && p.Id.ExpDate == expDate).ToList(); return setup.Single().AsDto();
But the first one runs a query with WHERE RowNumber <= 2 so it won't fail if extra rows are there. |
|
|
No, the two should definitely *not* be the same. In the second case you are asking LightSpeed to fetch all matching records into a list, then using LINQ to Objects to verify that the list has only one element. In the first case you are asking LINQ to LightSpeed to verify that only one entity meets the query criteria. Hence the WHERE RowNumber <= 2 criterion in the SQL query in the first case. Once we have two rows, that's enough to make Single fail. Fetching all the rows would be wasteful. |
|
|
Ah!! You are right I was mentally blocking the "=" part of the equation. You are getting at least two rows so I will get the failure that I want. |
|