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 have a parent Event entity with a collection of EventItem's. I can create an Event and call my Insert Event stored proc just fine. When I try to create and Event and then add an EventItem to it's collection thus:
Event e = new Event();
EventItem ei = new EventItem();
e.EventItems.Add(ei); // argggghhhh!!!
domain.InsertEvent(e); I get the following error (this is before I try to save it via stored procs): BlahBlah.Domain.Tests.DomainTests.Can_Insert_Event threw exception: Mindscape.LightSpeed.LightSpeedException: An error occurred when trying to assign a new Identity value to this entity. Check inner exception for details ---> System.InvalidCastException: Invalid cast from 'System.Int32' to 'System.Guid'.. This also happens if I try to set the Event on the EventItem: ei.Event = e; Both entities have Guid PK's. Most tables have int identity pk's so I have this in the .config:
identityMethod ="IdentityColumn" Ive tried overriding this on a per table basis but the Custom Table attribs in the designer dont seem to support this and I'm not sure if this is the problem anyway.
Ta |
|
|
You're right that this is an identity method issue. The IdentityColumn method is trying to assign a (temporary) integer ID, which can't be cast to a GUID. As you've surmised, the fix is to override the identity method on a per-table basis. We used to expose this in the designer but we've hidden it in LS3 because it seemed to confuse a lot of people who went around setting it on every individual table instead of at a context level. Unfortunately, this makes it a bit harder to use it in situations like yours where you really do need a per-table override. There are two ways to do it: 1. Create partial class declarations for Event and EventItem, and apply [TableAttribute(IdentityMethod=IdentityMethod.Guid)] via those partial classes. 2. Open the .lsmodel file in the XML editor, and add the identityMethod="Guid" XML attribute by hand to the Event and EventItem <entity> elements. We know this is a bit inconvenient and we're open to feedback as to whether we should restore it to visibility -- we just took it out because it was tempting people to overuse it. |
|
|
I tried #1 but I get a duplicate Table attribute error when I do that. #2 works swell. Having it in the designer would be my preference - old age = lazy programmer Cheers matey. |
|