我有这样的实体。我为这个样本简化了它们:
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; }
}
我有这样的架构:
第一个问题是:如何定义DbManger接口?我需要哪些方法?
建议的解决方案:为一个操作创建一个方法。 SearchProductByCompany,SearchProductByCategory等。如果我这样做,我会看到一些性能和架构问题。
第二个问题是:如何按城市和类别搜索产品?
建议的解决方案:如果我选择问题1的建议解决方案,我会想到这个问题的答案计划如下:
所有这些查询从Application到WCF到DbManager并返回。
第三个问题是:也许我需要具有非常深刻的硬选择逻辑的方法以及他的所有相关类及其相关类?
看起来像是复杂的搜索查询。
一般:
我看到了许多关于DAL的链接和答案,但大多数只是抽象和理论的,许多人都谈到了ORM。我理解ORM是什么,而DAL不是ORM不写关于ORM的。我需要更多样本如何在DAL中定义数据访问层,是否重用方法。通过具体的dal实现链接到良好的开源项目将会很棒。
答案 0 :(得分:0)