使用Linq2Sql的最佳方法是什么? [等候接听]

时间:2021-08-08 16:48:13

I'm struggling to think of a good way to use linq2sql, simply I want to use it, but I can't figure out whether it's best to wrap up the linq2sql generated classes inside my model classes providing some form of generic abstract base class / or interface for the common methods on my model classes like add, update, delete etc, or to extend the partial classes that linq2sql generated.

我很难想到一个使用linq2sql的好方法,只是我想使用它,但我无法弄清楚是否最好在我的模型类中包含linq2sql生成的类,提供某种形式的泛型抽象基类/或我的模型类上的常用方法的接口,如添加,更新,删除等,或者扩展linq2sql生成的部分类。

What design have people found most successful? and could you give a quick run down of those said designs?

人们发现哪种设计最成功?你能快速淡化那些设计吗?

(I know this is kind of subjective because everyone will have their own best ways, however , I'm not sure if it should be tagged as so. Feel free to edit and make a community wiki if you think it should be.)

(我知道这有点主观,因为每个人都有自己最好的方式,但是,我不确定它是否应该被标记为。如果您认为应该如此,请随意编辑和制作社区维基。)

2 个解决方案

#1


8  

Personally, I wrap Linq2SQL in the repository pattern.

就个人而言,我将Linq2SQL包装在存储库模式中。

#2


3  

Depending on the complexity of your application you may or may not need to use anything other than the generated classes for your ORM. I find that I am able to happily live with the generated classes, extended by partial methods and by wrapping the data context with a wrapper (and possibly extended if I need to add common functionality) to improve testability. Most of my applications are relatively simple from a database perspective, though.

根据应用程序的复杂程度,您可能需要或不需要使用ORM生成的类以外的任何其他内容。我发现我能够愉快地使用生成的类,通过部分方法扩展并使用包装器包装数据上下文(如果我需要添加常用功能,可能会扩展)以提高可测试性。但是,从数据库的角度来看,我的大多数应用程序都相对简单。

#1


8  

Personally, I wrap Linq2SQL in the repository pattern.

就个人而言,我将Linq2SQL包装在存储库模式中。

#2


3  

Depending on the complexity of your application you may or may not need to use anything other than the generated classes for your ORM. I find that I am able to happily live with the generated classes, extended by partial methods and by wrapping the data context with a wrapper (and possibly extended if I need to add common functionality) to improve testability. Most of my applications are relatively simple from a database perspective, though.

根据应用程序的复杂程度,您可能需要或不需要使用ORM生成的类以外的任何其他内容。我发现我能够愉快地使用生成的类,通过部分方法扩展并使用包装器包装数据上下文(如果我需要添加常用功能,可能会扩展)以提高可测试性。但是,从数据库的角度来看,我的大多数应用程序都相对简单。