Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing LINQ-to-SQL classes/models between multiple projects in a solution

I have multiple C# projects in a Visual Studio solution right now that will all use the same SQL Server database.

What is the proper way to share LINQ-to-SQL classes between projects?

I'm considering just copying the dmbl files into each project, but I think that may be too redundant. Is there a better way to approach this?

like image 982
Maxim Zaslavsky Avatar asked Feb 07 '26 02:02

Maxim Zaslavsky


1 Answers

I suppose you need to share database access code between projects not linq-2-sql classes as they are.

Build Data Access Library (DAL) that expose operations over database that are implemented via linq-2-sql classes rather then expose classes.

I'd suggest to use Repository Pattern

Refer DAL library from projects you want.

like image 63
Andrew Florko Avatar answered Feb 09 '26 03:02

Andrew Florko