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've got a standard single table inheritance scenario here - must be doing something wrong... I'm trying to expose the discriminator colum on a base entity as an enum. Reason being; I send out a list of BaseEntity via WCF. ie GetAnimals(). I want to augment the BaseEntity with the enum based on discriminator type. That way the client can determine what type each entity in the list is, and call the correct WCF method to retrieve the full dto. ie animal.Type = AnimalType.Dog therefore call GetDog(animal.Id). hope that all makes sense on a friday afternoon. ;) I've wired up the UDT in the LS model and the model all compiles but i get the following at runtime: stack trace: System.InvalidCastException: Invalid cast from 'System.Int32' to 'Model.AnimalType'.
happy to provide more details/screenshot if you need. cheers justin |
|
|
This is not currently supported. The discriminator field must be an integer, not an enum. Remember, however, that LightSpeed is interested only in *field* types. You can therefore still have the enum in your public API by setting the property to FieldOnly in the designer, and writing your own wrapper: public AnimalType AnimalType { |
|
|
ok, that works great. except..... now the Dto has an int AnimalType and the entity has an AnimalType AnimalType. :) can i control what gets pushed into the dto? i was expecting if the entity has a property marked up as fieldonly that it would _not_ appear in the dto - and then i could wrap the dto much the same as the entity... btw, big ups to you guys on always fast responses to the forums. :D |
|
|
mmm, k. fixed that. i've updated the DataContracts.vm template. lines 90 and 103, surrounded the field generation with #if ($field.GenerateProperty) looks like a bug methinks but this fix seems to work. :) thanks for pointing me on right track. |
|
|
oops, missed one. also fix line 25 to: #if ($field.GenerateProperty) |
|
|
Good point. I agree that would be better behaviour for the DTO. Unfortunately, I don't think we can change it at this stage because it could result in breakage to existing models. Maybe in 4.0. So for now the only way to control what gets pushed into the DTO at the moment is to edit the code generation templates as you have done. I'll see if we can get the underlying discriminator enum limitation removed so that this is less of an issue for you in future. |
|
|
Has this been fixed yet. I would like to use an enum as a discriminator but it causes all kinds of chaos when I do. The (lack of) error message doesn't help either. I just get a 'There were validation errors, continue save?' message with no explantion as to what the problem is. Sean |
|
|
Yes, this is now in the current nightly build. Note that you must reference your enum type as a User Defined Type, and set the Discriminator Type to that type. You will also need to qualify the enum value in the Discriminator Value box, i.e. be sure to write TestType.Lung rather than just Lung. |
|
|
Thanks. All working now. |
|