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 have several entities that I am encapsulating into a core library. Then I have a business layer that handles working with those entities and translating the entities to some data-only structures that get consumed by the various client applications we have. In order to hide the underlying lightspeed layer from any clients and to avoid having multiple search methods such as GetById, GetByName, GetBySomethingElse, when a client wants to search for an entity they populate one of the data structures with just the values that they are searching for and pass that to the business layer. Mostly this has worked out well but Ive run in to this latest issue. Here is the basic Entity: int Id The data structure consumed by the client pretty much matches the Entity structure. I have a generic Get method in the base business class that calls a Search method in to derived classes. It then calls the Where method of the entity collection in the specialized Unit of Work (DomainUnitOfWork.FrequentUsers.Where(Search(data))). Here is the search method:
So presumably they can specify any or all of the values and only objects matching that criteria will be returned. The problem is with the int? Number field. It may or mat not be specified. In this case it is not getting specified but UserId is. This should normally create a query that simply has "Where UserId=123". But an error is getting thrown before the SQL can even be generated and logged. The exception is an InvalidOperationException and the message is 'Nullable object must have a value'. Here is the relevant portion of the stack trace. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Nullable I would expect the clause to just evaluate to true since obj.Number.HasValue returns false. Any ideas? |
|
|
It looks like the process of evaluating the 'local' variables when we traverse the LINQ expression is not performing short-circuiting. We'll look into this but the workaround is to evaluate the 'local' variables yourself in a way which is null-safe:
Let us know if you still run into problems. |
|
|
Do you have any update about the "short-circuiting" and when it might potentially be available? |
|
|
We've already made some changes which improve behaviour in simple cases, but we don't have an ETA for your more complicated composite case. Sorry. |
|
|
Ok, thanks. I'll be sure to upgrade to the latest nightly |
|