2
votes

I am using Entity Framework POCO to generate some self-tracked data objects, and I exposing these objects from a WCF service interface.

I have EntityA & EntityB, which both map to different tables in the database.

I would like both EntityA and EntityB to inherit from a base 'Entity' class, so that I can implement a simple WCF service interface like this:

void Save(Entity entity)
IEnumerable<Entity> GetEntities()
void Delete(Entity entity)

In the entity framework designer I add an entity called 'Entity' and make 'EntityA' & 'EntityB' inherit 'Entity'. However, entity framework complains because 'Entity' does not have a key, and is not mapped to a table in the database.

Is there anyway that I can give these two entities a base class, which is not represented in the database?

Thanks in advance!

1

1 Answers

2
votes

Looks like I've managed to answer my own question!

This is simply done with partial classes: 1. Define the Entity class yourself in code. 2. Create a partial class for EntityA and make it inherit from Entity.

And voila! it works :-)