Ingó Vals
Ingó Vals

Reputation: 4898

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 class 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?

Upvotes: 2

Views: 491

Answers (1)

Henric
Henric

Reputation: 1410

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

Upvotes: 2

Related Questions