2

I have probably written the same LINQ to SQL statement 4-5 times across multiple projects. I don't even want to have to paste it. We use DBML files combined with Repository classes. I would like to share the same Library across multiple projects, but I also want to easily update it and ensure it doesn't break any of the projects. What is a good way to do this? It is OK if I have to change my approach, I do not need to be married to LINQ to SQL and DBML.

We have both console apps and MVC web apps accessing the database with their own flavor of the DBML, and there have been times when a major DB update has broken them.

Also, since currently each project accesses the DB from itself, which is sometimes on another server, etc. Would it be possible to eliminate the DB layer from being within each project all together? It might help the problem above and be better for security and data integrity if I could manage all the database access through a centralized application that my other applications could use directly rather than calling the database directly.

Any ideas?

MetaGuru
  • 42,847
  • 67
  • 188
  • 294
  • 1
    regarding not breaking projects, you could/should use unit/integration tests, I think any solution will guarantee this by it self. If you really need separate dbml's for different projects, make them update automatically by using sqlmetal (that' how we do it, also after regenerating dbml's, we run xslt transformation to adjust generated dbml, so we never touch dbml manually). – Giedrius Sep 19 '11 at 13:55

1 Answers1

1

The way I handle this is using WCF Data Services. I have my data models and services in one project and host this on IIS. My other projects (whatever they may be) simply add a service reference to the URI and then access data it needs over the wire. My database stuff happens all on the service, my individual projects don't touch the database at all - they don't even know a database exists.

It's working out pretty well but there are a few "gotchas" with WCF. You can even create "WebGet" methods to expose commonly used methods via the service.

Let me know if you want to see some example code :-)

eth0
  • 4,977
  • 3
  • 34
  • 48
  • Well, it depends on how much data you have and how you behave with it, in some cases such solution can be real performance bottleneck (not my test and not sure know how real it is: http://stackoverflow.com/questions/3916983/how-to-improve-wcf-data-services-performance, but my experience shows, that there are performance issues, just never measured real values), although it seems nice from architecture view. – Giedrius Sep 19 '11 at 13:50
  • Yes, of course you must take in to account the performance, especially over the Internet. I've used this approach for relatively small internal applications. – eth0 Sep 19 '11 at 19:24