使用数据访问层进行复杂搜索

时间:2012-07-27 08:46:06

标签: database design-patterns architecture data-access-layer data-access

我有这样的实体。我为这个样本简化了它们:

public class City
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class Street
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int CityId { get; set; }
    public City City { get; set; }    
}

public class Address
{
    public int Id { get; set; }
    public int CityId { get; set; }
    public City City { get; set; }
    public int StreetId { get; set; }
    public Street Street { get; set; }
    public string House { get; set; }
}

public class Company
{  
    public int Id { get; set; }
    public string Name { get; set; }
    public int AddressId { get; set; }
    public Address Address { get; set; }
}

public class Category
{  
    public int Id { get; set; }
    public string Name { get; set; }
    public int ParentId { get; set; }
    public Category Parent { get; set; }
    public List<Category> Children { get; set; }
}

public class Product
{  
    public int Id { get; set; }
    public string Name { get; set; }
    public int CategoryId { get; set; }
    public Category Category { get; set; }
    public int CompanyId { get; set; }
    public Company Company { get; set; }
}

我有这样的架构:

  1. 申请
  2. WCF服务又名DbManager包装器
  3. DbManager又名数据访问层
  4. 第一个问题是:如何定义DbManger接口?我需要哪些方法?

    建议的解决方案:为一个操作创建一个方法。 SearchProductByCompany,SearchProductByCategory等。如果我这样做,我会看到一些性能和架构问题。

    第二个问题是:如何按城市和类别搜索产品?

    建议的解决方案:如果我选择问题1的建议解决方案,我会想到这个问题的答案计划如下:

    1. 致电DAL以获取所选城市的地址列表。
    2. 致电DAL以获取所选地址列表的公司列表。
    3. 致电DAL以获取所选公司列表的产品列表。
    4. 调用DAL按类别过滤所选的产品列表。
    5. 所有这些查询从Application到WCF到DbManager并返回。

      第三个问题是:也许我需要具有非常深刻的硬选择逻辑的方法以及他的所有相关类及其相关类?

      看起来像是复杂的搜索查询。

      一般:
      我看到了许多关于DAL的链接和答案,但大多数只是抽象和理论的,许多人都谈到了ORM。我理解ORM是什么,而DAL不是ORM不写关于ORM的。我需要更多样本如何在DAL中定义数据访问层,是否重用方法。通过具体的dal实现链接到良好的开源项目将会很棒。

1 个答案:

答案 0 :(得分:0)

我发现这篇关于WCF数据服务http://www.codeguru.com/csharp/.net/net_wcf/article.php/c17045/Windows-Communication-Foundation-WCF-Data-Services.htm的文章看起来就像我需要的那样。