views:

80

answers:

1

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  A: 

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; } 
    }
}
Tomas Lycken
In ado.net entity framework you (correct me if im wrong) are not allowed to implement your own getters and setters for your own fields as they are already implemented in the auto-generated file. Is there a way that you could without subclassing or is there a "right" way that I should be doing it?
mglmnc