2

I am using Entity Framework in my dataaccess layer, i also use this as my object model.

psudo object model:

public class Item{
    public string ID{get;set;}
    public string Name{get;set;}
    public Xml Data{get;set;}
}

The Data property is the key here. i would like to be able to do this:

Psudo:

var item = Items.Get(id: 1);
var xmlValue = item["key"];

I would like to be able to extend the EF generated class Item with a new property where i use some logic to get a value by key from the xml.

My problem is:

  1. I find EF data model not very easy to work with and when i want to update the Item table, i cannot be sure my extended logic will stand.
  2. I dont think i want to add an extracted model and do a convert the EF Item to My.Item every time. This will be a heavy opeartion if the table gets big.

What is a good way to extend the EF object model?

that i dont

1 Answer 1

4

You could just use a partial class and define the extra fields / properties.

Converting from EF Item to your item is trivial if the fields are the same, you could just use Automapper

i'm leaning towards the partial class solution though.

Sign up to request clarification or add additional context in comments.

1 Comment

You could also use extension methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.