具有许多参数的 C# 数据访问 GetAll() 方法

Posted

技术标签:

【中文标题】具有许多参数的 C# 数据访问 GetAll() 方法【英文标题】:C# Data Access GetAll() methods with many parameters 【发布时间】:2011-06-07 00:17:06 【问题描述】:

在数据访问层有如下方法是很常见的:

    Tuple<int, IList<Media>> GetAllWithFilter(int? page, string folderName, string title, string fileName, string author, string keywordTitle, int type, int fileType, int rowsPerPage, Guid keywordId, string sortField = null, string sortDir = null);

每次添加新属性时,它都会变得越来越混乱

保持这些方法的可读性和可维护性的良好做法是什么?

谢谢

【问题讨论】:

【参考方案1】:

为什么不创建一个包含所有过滤器属性的对象并将其传递出去?

【讨论】:

【参考方案2】:

我认为这个会有所帮助。 Query pattern

【讨论】:

以上是关于具有许多参数的 C# 数据访问 GetAll() 方法的主要内容,如果未能解决你的问题,请参考以下文章