除了dbml文件之外,您还可以对您的DAL做什么呢

时间:2021-04-06 21:08:57

NOTE: I am not an expert, so if you feel this question stupid/lame please forgive and mind your business. :)

注意:我不是专家,所以如果你觉得这个问题很愚蠢,请见谅。:)

Ok, as all video tutorials tell, create a LinqToSqlClasses item (dbml) file. drag tables and we are done here.

好的,正如所有的视频教程所讲的,创建一个LinqToSqlClasses项目(dbml)文件。拖拽表就完成了。

But in my case (or probably in all real world scenarios), we need more from our Data Access Layer than just the auto generated classes, right?

但是在我的例子中(或者可能在所有现实场景中),我们需要的不仅仅是自动生成的类,对吧?

For Example: In a simple accounting software: i have a Accounts Table and a AccountingTransactions Table,

例如:在一个简单的会计软件中:我有一个会计表和一个会计事务表,

Now to get any account's ledger we need to write a pretty Lengthy sql query, same goes for trial-balance, day book, and Single Vouchers et cetera.

现在,要得到任何帐户的分类账,我们需要编写一个非常长的sql查询,试算平衡表、日记帐和单凭证等等也是如此。

What can we do in DAL to optimize these queries to have best performance.

我们可以在DAL中做什么来优化这些查询以获得最佳性能。

1 个解决方案

#1


1  

I would recommend using Entity Framework over Linq to SQL.

我建议使用实体框架而不是Linq到SQL。

But in both these cases, you have the power of Linq for such queries. Plus this gives you better designer support (intellisense, strong types, compile time checking)

但在这两种情况下,您都可以使用Linq进行此类查询。此外,这还为您提供了更好的设计器支持(智能感知、强类型、编译时检查)

EF or LinqToSQL becomes the lower level DAL and on top of this you would use the Repository pattern to call your Data Objects in a loosely coupled way. You could also add special methods for certain repositories to query data in a specific way if this needs to be encapsulated.

EF或LinqToSQL成为更低级的DAL,在此之上,您将使用存储库模式以松散耦合的方式调用您的数据对象。如果需要封装数据,还可以为特定的存储库添加特殊的方法,以便以特定的方式查询数据。

You should search SO for the repository pattern with Entity Framework or LinqToSql, you'll find a couple of implementations.

您应该使用实体框架或LinqToSql来搜索存储库模式,您将会找到一些实现。

See this answer : Advantage of creating a generic repository vs. specific repository for each object?

看看这个答案:为每个对象创建通用存储库和特定存储库的优点?

#1


1  

I would recommend using Entity Framework over Linq to SQL.

我建议使用实体框架而不是Linq到SQL。

But in both these cases, you have the power of Linq for such queries. Plus this gives you better designer support (intellisense, strong types, compile time checking)

但在这两种情况下,您都可以使用Linq进行此类查询。此外,这还为您提供了更好的设计器支持(智能感知、强类型、编译时检查)

EF or LinqToSQL becomes the lower level DAL and on top of this you would use the Repository pattern to call your Data Objects in a loosely coupled way. You could also add special methods for certain repositories to query data in a specific way if this needs to be encapsulated.

EF或LinqToSQL成为更低级的DAL,在此之上,您将使用存储库模式以松散耦合的方式调用您的数据对象。如果需要封装数据,还可以为特定的存储库添加特殊的方法,以便以特定的方式查询数据。

You should search SO for the repository pattern with Entity Framework or LinqToSql, you'll find a couple of implementations.

您应该使用实体框架或LinqToSql来搜索存储库模式,您将会找到一些实现。

See this answer : Advantage of creating a generic repository vs. specific repository for each object?

看看这个答案:为每个对象创建通用存储库和特定存储库的优点?