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 a table [ClassState] that has a nullable Foreign key to a table called [MetaState]. When I try to retrieve a collection of ClassState objects from the database that include a record with a null value in the MetaStateId column, I get the following error. Message= {"Unable to materialize field [MetaStateId] on type [StatusSpike.ClassState]. See inner exception for details"} InnerException = {"Object cannot be cast from DBNull to other types."} I am using version 2.1.876.10051 of LightSpeed and SQL 2k5. Thanks in advance. |
|
|
In your class definition for ClassState, is MetaStateId declared as an "int" or an "int?" / Nullable<int>? In order to represent a nullable foreign key it must be declared as the latter. If it is already declared as an "int?" / Nullable<int>, could you send us the SQL CREATE TABLE scripts and entity definitions (.cs) for ClassState and MetaState please so we can try to reproduce please? Thanks! |
|
|
HI Ivan, You were right the MetaStateId was not set to int?. I had dragged the tables across from my database onto the designer and assumed that the IsNullable property had been set on the relationship between the two entities. Thanks for you speedy response. Cheers, Stuart |
|
|
That's a reasonable assumption! The designer is indeed meant to spot when a foreign key is nullable and set the association IsNullable property accordingly. Thanks for letting us know about this -- I've logged a bug and will look into it (though not immediately). |
|