0

I have table name Transaction in the DB. I want to have 2 subclasses TransactionA and TransactionB. I've made it as described here: http://www.robbagby.com/entity-framework/entity-framework-modeling-table-per-hierarchy-inheritance/comment-page-1/#comment-607

As I use T4 templates I've generated self-tracking entities.

Everything is okay but one thing. I can see generated entities TransactionA and TransactionB but I cannot see them in the context object (ObjectContext). Is it normal? If so, how could I get TransactionB from the table using context if only Transaction class is accessible?

Thanks

Youp Bernoulli
  • 5,303
  • 5
  • 39
  • 59
mimic
  • 4,897
  • 7
  • 54
  • 93
  • 1
    Be warned, queries against Transaction (in other words against the base class and not the derived classes will be poor) for example, context.Transactions.Count() will do a funky bunch of joins between all three tales in your model, in though such is not required! – Ralph Shillington Jul 21 '11 at 20:16

1 Answers1

1

This is as expected. Transaction A en B derive from the baseclass Transaction. In your entity model you can access them through the collection of Transactions like this:

Context context = new Context();
List<TransactionB> list = context.Transactions.OfType<TransactionB>().ToList();
Youp Bernoulli
  • 5,303
  • 5
  • 39
  • 59
  • Yes, that what I'm doing but why context doesn't have the TransactioB collections after I've added this entity into the model? It would be more logical I think. – mimic Jul 21 '11 at 20:13
  • I don't know exactly why it is. But it is by design. It could be more logical, agree. But the answer I provided answers your question, isn't it? – Youp Bernoulli Jul 21 '11 at 20:14
  • http://blogs.msdn.com/b/adonet/archive/2007/03/15/inheritance-in-the-entity-framework.aspx can give some more insight – Youp Bernoulli Jul 21 '11 at 20:17