When using code-first EntityFramework, I need one property to be set before the others – how do I specify the order that it calls the property sets, when it is creating the objects from the database?
E.g.
public class Person
{
public string Name { get; set; }
public string Something
{
get { return something; }
set
{
something = value + " for " + Name;
}
}
private string something;
}
In the code above, I need the Name property to already have been set by the time it sets the Something property.
This isn’t the actual example – I know there are other ways to achieve that literally, but I’m not after those, just how I can tell EF to set Name before Something.
I am trying to understand the context of your question. I am going to make the assumptions that:
I think your mistake here is trying to add a derived portion to the value you are looking to store. Calculate the pretty name in another property, or on a get:
UPDATE had an example overriding the get on the Something Property, but removed as I feel it is bad practice.
Finally – (and here is where I could use some help as I have not run into a situation where I needed to do something like this) my guess is that you do not need to be storing the partially calculated property
Somethingin the way you were attempting, but if you do need to, I think additional detail might help someone provide you with a better answer.UPDATE 2
As described in my comments – not sure this would work, and it feels very wrong, but you could try something like:
and then in the setter:
Again this will depend on you needs, and would not satisfy any need to pass this value in, and I am not sure this is a great idea.