LINQ to SQL: Can I program against a interface even when using LINQ-2-SQL
I will use LINQ-to-SQL when the database is ready and use the entities there as models in my aplication. I'm trying to program against a interface to make changes to the program easier and I just realized that if I would later change from LINQ to something else I would have to create new model objects that would represent something very similar to the LINQ entities.
So I thought of creating interfaces for each entity and expose the properties and methods I would use in the program and aren't LINQ specific. But when I would apply this interface to the entity clas开发者_运维技巧s would the implementation automatically bind to it's properties.
I'll give you an example to explain better.
I have table Cars that amongst others has the columns producer, type and wheels
So I make the interface ICar
public interface ICar
{
string Producer { get; set; }
string Type { get; set; }
int Wheels { get; set; }
}
The Car entity object will have these exact properties so will that work as the implementation of these properties or will they be defined seperatly so you get ICar.Producer and Car.Producer in the class?
This might be helpful: Linq to Sql, Programming Against an Interface and the Repository Pattern
First link is broken, check here instead: ORM and Repository pattern
精彩评论