0
votes

I have a persistent class that looks like this:

public partial class Unit
{
    public string Name { get; set; }
    public long LengthInMM { get; set; }
    public decimal VolumeCoefficient 
    {
        get { return LengthInMM * LengthInMM * LengthInMM; } 
    }
}

Now the derived field (VolumeCoefficient) never gets explicitly assigned. How do I save it in ADO.NET entity framework?

I thought of subclassing the Unit class and overriding the getters and setters but that seems too messy.

1
Why would you want to save the value of a computed property? - Jørn Schou-Rode
Because some of the derived fields I am saving are not as concrete as this example. For example a price field in my domain will be derived by a product of commodity prices that may change over time and a fixed coefficient. - mglmnc

1 Answers

1
votes

Why don't you just declare it another part of your partial class?

Generated by the designer:

public partial class Unit
{
    public string Name { get; set; }
    public long LengthInMM { get; set; }
}

In a different file

public partial class Unit
{
    public decimal VolumeCoefficient 
    {
        get { return LengthInMM * LengthInMM * LengthInMM; } 
    }
}