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 Guys, I'm not sure if I have misunderstood the point of the Value Object - but I have used this and created a Value Object called "Salary" with three properties called, Low, High and Description. This Salary Object is shared between two tables. Creating a DB from the LightSpeed modeller does exactly what I expected, and has added these fields directly in to the table structure. The problem I have is that the LightSpeed model seem to have the Salary Value Object as read only, with only get, here is the generated code... [Serializable]
But I am using this code in MVC model and it cannot set the values - is there a setting somewhere I can set that will make the ValueObject have setters aswell? Thanks for your help as usual. |
|
|
Value objects have value semantics, not identity semantics, and should be immutable. If someone's salary changes, this is modelled by setting their Salary property to a new Salary. (The principle is that Bob's salary is changing from $1000 to $2000, not that the value of $1000 is changing to be $2000.) So if you're working with a framework that can't handle immutable values, then I'm afraid you'll need to resort to hand coding. For each property in the value type, set Generation to None, and implement the mutable field and get/set property in the partial class. (You should still leave the value object properties in the model, even though we won't generate the code for them, so as to get database sync.) However, we're not sure that just making Salary mutable will be the best solution to your problem. Obviously it's possible to set an entity property of type Salary from MVC code, so we assume this either a data binding issue (in which case it may depend on which model binder you are using) or that you have a seperate and reusable form for editing Salary objects. If you can let us know a bit more about where you're hitting a problem then one of our ASP.NET MVC gurus may be able to give you better advice than I can! |
|
|
Thanks Ivan, I have set the field generation to none and hand coded now, and it's working as I originally expected. I think I have perhaps misused this method - I just wanted to effectively use it exactly the same way it is created in the DB as a bunch of extra fields, but keep it as an entity in the model as it was tidier and used more than once. Cheers |
|