ORMValueTypeMismatchException was unhandled by user code

Posts   
 
    
PaulWilson
User
Posts: 13
Joined: 20-Aug-2010
# Posted on: 20-Aug-2010 08:56:01   

The value is of type 'System.DBNull' while the field is of type 'System.Int32'

How can I find out which value is not set correctly? It's not instantly obvious and is almost certainly in a collection owned by the item i'm saving recursively.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Aug-2010 10:53:57   

Your question is too short to be understood, sorry.

Would you please add more details about the issue you are facing.

PaulWilson
User
Posts: 13
Joined: 20-Aug-2010
# Posted on: 20-Aug-2010 10:57:54   

I have an entity that I am saving to a SQL Database.

I call entity.Save(true) so it saves recursively.

Watching profiler it saves the top level entity, but there is a child entity that is causing a problem. I don't know which one.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Aug-2010 11:15:20   

This seems to be coming from the Built-In field validation.

Which runtime library version (build number) are you using? And could you please post some code snippets?

PaulWilson
User
Posts: 13
Joined: 20-Aug-2010
# Posted on: 20-Aug-2010 12:42:52   

I have a "TeamEntity" that owns a collection of "TeamDepartmentEntity" which is a type two slowly changing dimension linking the Team and Department Entities.

The process I'm doing is to assign a team to a new Department. This involves finding the current TeamDepartmentEntity and setting the end date to "Yesterday" and adding a new TeamDepartment entity that is valid from today.

I am updating the Team entity and saving recursively when I get the error. The TeamEntity is pretty simple with a TeamId and a TeamName. The TeamDepartment is also pretty simple with TeamId, DepartmentId, StartDate and EndDate. The Department Entity has DepartmentId, DepartmentName.

It's nearly certain that I'm not setting something I should, however the question is centered around how can I find out what it is. I can look at the table in the database and ascertain the nullable columns etc... I can reflect the entities and find out what is set to what, but there are many many properties that I'd have to check. The exception is generated by LLBLGen so clearly at the point it happens the framework knows the name of the field it's having a problem with. How can I tell?

I should add, the unhandled exception can be worked around by deleting the relevant entities before refreshing the schema. That way, it never has the matching problem and doesn't throw. If I get a chance to reproduce it reliably I'll post it on the forum.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Aug-2010 08:26:10   

If I understand, TeamDepartment is an m:n table that links Team and Department tables right? Maybe you are not creating that m:n relation correctly.

This is how an m:n entity should be added (copied from the How do I... section):

DepartmentEmployees newDepEmp = new DepartmentEmployees();
newDepEmp.Employee = employee;
newDepEmp.Department = department;
// the 3 entities are now linked. We can now save recursively any of the three (doesn't matter) 
// to save the relation in the database.
adapter.SaveEntity(employee);

Anyway, would be helpful if you post the relevant code snippet and the full exception message and stack trace.

What LLBLGen version and runtime library version are you using? (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722)

David Elizondo | LLBLGen Support Team
PaulWilson
User
Posts: 13
Joined: 20-Aug-2010
# Posted on: 03-Sep-2010 13:37:10   

This is related to using triggers with SCOPE_IDENTITY and is solved by updating the Field Mapping of the Entity and altering 'sequence' to @@IDENTITY (assuming that the trigger doesn't change this value).

Please see http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=18605