I am building a c# - linq - sql server winforms/asp.net application, accessing a database. I would like my business logic layer to be easily testable, and that means not littering it with Linq database queries everywhere. What design patterns/ best practices are available for the following use cases - inserting/updating a new object -开发者_JAVA技巧 searching for an object - loading a bunch of related data into a sort of "presentation" object that could be displayed by various views ?
Here is a six part article about Architecting LINQ To SQL Applications
The Repository Pattern is the one I think you're looking for
I recomend to view video lessons http://www.asp.net/mvc/videos#ASP.NET%20MVC%20Storefront%20Starter%20Kit Part 1-3 about services/repositories/filters. It's good solution.
Look into putting your database calls into a set of classes implementing a common interface (Repository pattern is a common way to do this). Then you can mock these objects when running tests. Just make sure the repositories themselves are tested somewhere too :)
精彩评论