views:

26

answers:

1

Using Nerd Dinner as an example:

private NerdDinnerDataContext db = new NerdDinnerDataContext();

public IQueryable<Dinner> FindAllDinners() 
{
    return db.Dinners;
}

Is it not bad practice to directly expose the entity class Dinner here? I think it is better for the repository to return an IDinner.

So my question is, how can I make the auto-generated entity classes expose my interface?

+1  A: 

As far as I know, the only way would be to modify the template from which the code is generated. Another possibility is partial classes. The code generator creates partial classes. You could create another partial class that contains the interface you want. I believe this will work.

Randy Minder
Yeah, that, or create wrapper classes around all of the generated ones. I think maybe the Linq-To-Entities framework available with .NET 4 and Visual Studio 2010 can do this better, but I don't remember where I read it.
AHM