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 get the following exception: Unable to materialize field [LockVersion] on type [mcSphere.WebServer.DataServices.Domain.Model.Developer]: field is type 'System.Int32' but database returned type 'System.DBNull'. Check your table has an Id column and that your mappings are correct. See inner exception for details. I have got two tables connected via a one-to-many association. I set for some fields an aggregate name, the one-to-many association is lazy loaded. The LockVersion is not null at the DB. I get this SQL logged out: SELECT If I select the entity without using "WithAggregate" the error disapears. Fur sure I get one select for each access to a lazy loaded field (the one with the aggregate name specified) If i execute the sql at the SSMS, the Developer.LockVersion is "0". Any Ideas?
|
|
|
Could you post your Developer class code please? Thanks! |
|
|
[Serializable] |
|
|
Hmm, I'm not able to reproduce this. Is there a single or class table inheritance in play? This kind of error can result from a known issue if you have sibling classes in the hierarchy containing fields with the same name. Otherwise, could you provide us with a small buildable console or NUnit test project, and a sample database, that replicate the issue? Thanks! |
|
|
I send you a download link for the test project.
|
|
|
Thanks for the repro. Although it is clearly an error that LightSpeed is trying to load a NULL LockVersion, and we will investigate further, the code you're using contains an uneasy mix of server-side and client-side processing, and by changing this you can easily work around the bug. Specifically, this code: select is using client-side Funcs rather than expressions. Change it to: select and the problem goes away (and the projection will be carried out on the server). Alternatively, if you need to be able to use client-side Funcs, throw in an AsEnumerable(): var tempList = (from This will be no less efficient than your current code because your select is already running client-side (and developers already has the paging bits in it). |
|
|
Thanks for having a look at it. The repo is a "striped down to the problem" version of my original code. In my orignal code I pass the IQueryable<T>, getTheId and getTheName to a function which fills up a autocompletion combobox within a web service. It looks something like that one: public void AddItems<TEntity>(RadComboBoxData comboBoxData, IQueryable<TEntity> items, Func<TEntity, string> getTextFunc, Func<TEntity, string> getIdFunc, ...) { IList<RadComboBoxItemData> toAddItems = (from ) }
where the calling code looks something like this:
using (IUseCaseController<EntitiesUnitOfWork> controller = CreateNewUseCaseController()) ... So I changed the function to: public void AddItems<TEntity>(RadComboBoxData comboBoxData,IEnumerable <TEntity> items, Func<TEntity, string> getTextFunc, Func<TEntity, string> getIdFunc, ...)
and the call to: using (IUseCaseController<EntitiesUnitOfWork> controller = CreateNewUseCaseController()) ...
And it is working. Thanks again!
|
|