I have looked over the Repository pattern and I recognized some ideas that I was using in the past which made me feel well.
However now I would like to write an applicat
You don't have to use the LINQ to SQL generated code, you can decorate your own classes with the necessary ColumnAttributes or use an external XML mapping file.
Not exactly the same scenario, but I'm working to create a custom tool that based on a XML file will generate an OO model. My approach is to use LINQ to SQL behind the scene and since I'm generating the code automatically it would be easy to use another mechanism for let's say MySQL data source. Since it's not supported by LINQ to SQL you will have to write the data access code manually, but the client code that will use the OO model will change in any way.
Could your Entity classes implement IProduct, IUser, IOrder etc. interfaces that would be declared in your "Interfaces" assembly? This way the IRepository interface references only the business object interfaces (i.e., returns collections of IProduct etc.) and the "Interfaces" assembly is decoupled from your other implementation-specific assemblies.
I don't know if this is exactly what you want, but you may want to take a look at Rob Conery's MVC Storefront code. He uses a variant of the repository pattern with a linq provider. He maps the LINQ to Sql objects to domain objects and then returns the domain objects from the repository provider to a service layer which wraps the provider allowing him to work some logic on the data returned before it hits the business layer.
MVC Storefront Webcasts
Code
To me it sounds like you want the providers to return DTOs and then you want to map the DTOs to the domain objects in the repository/service layer. If this is the case you could map your LINQ to SQL provider to the DTOs, have it return them, then map the DTOs to domain objects in the repository/service layer. This should work just fine, but it may become tedious as you now would have 2 mapping layers.
In this case you would have: ProductService, which takes an IProductRepository. It evokes methods on the IProductRepository to get back your DTOs. It then maps the DTOs to the real business objects and returns them to the calling code.
I found a fantastic blog post (with lots of good code) about this here: http://iridescence.no/post/Linq-to-Sql-Programming-Against-an-Interface-and-the-Repository-Pattern.aspx
You can create an external XML file mapping the database to any class:
<?xml version="1.0" encoding="utf-8"?>
<Database Name="DbName"
xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
<Table Name="DbTableName">
<Type Name="EntityClassName" >
<Column Name="ID" Type="System.Int64" Member="Id"
DbType="BigInt NOT NULL IDENTITY" IsPrimaryKey="true"
CanBeNull="false" />
<Column Name="ColumnName" Type="System.String" Member="PropertyA"
DbType="VarChar(1024)" CanBeNull="true" />
</Type>
</Table>
</Database>
And then pass the XML to a DataContext class:
using (var cn = GetDbConnection())
{ var mappingSrc = XmlMappingSource.FromReader(xmlReader);
using (var db = new DataContext(cn, mappingSrc))
{ var q = from entity in db.GetTable<EntityClassName>()
where entity.PropertyA = "..."
select entity.ID;
}
}