Jim
Jim

Reputation: 2828

Extending EF Poco Class

I am learning EF 4 staff and really got stacked. I am using Code First approach eg.

public class Machine{
 public int A{get;set;}
 ...
}

I am trying to implement business logic in additional property based on the A property (eg. B = A+5) and present it in WPF datagrid. This new property doesn't need to be stored in database at all. How would I do that (e.g. with partial class )? Any examples?

Upvotes: 0

Views: 491

Answers (2)

np-hard
np-hard

Reputation: 5815

If you are using EF 4.1 you can just use the not mapped attribute. If you are using the edmx designer, i beleive you can remove the column name it assigns to in the model viewer table mappings

Upvotes: 1

LueTm
LueTm

Reputation: 2380

public class Machine
{
    public int A { get; set; }

    [NotMapped]
    public int B
    {
        get
        {
            return A + 5;
        }
    }
}

This should work.

Upvotes: 3

Related Questions