当前位置:编程学习 > C#/ASP.NET >>

某1控件包含多个数据模型中的属性,应该怎么办?

asp.net webform应用程序中,有Model、DAL、BLL、和Web层
例如:Model中有
ProductCategoryInfo(产品类型模型)(包含CategoryID, CategoryName)
ProductInfo(产品模型)(包含ProductID, ProductName, Price, Descript)

如果Web层中某GridView控件仅需要绑定产品信息就很好办,只需要 GridView.DataSource = IList<ProductInfo>();就行了
但是如果我在GridView中 要显示的信息包括 ProductID, ProductName, Price, Descript, CategoryName 包含多个数据模型中的信息,那应该怎么办呢?

求真相!
--------------------编程问答--------------------  public class ProductInfo{

private ProductCategoryInfo  type;
 public ProductCategoryInfo Type
        {
            get { return type; }
            set { type= value; }
        }
} --------------------编程问答--------------------
引用 1 楼  的回复:
public class ProductInfo{

private ProductCategoryInfo type;
 public ProductCategoryInfo Type
  {
  get { return type; }
  set { type= value; }
  }
}
--------------------编程问答-------------------- 联合查询后返回综合性的产品信息模型(Model)列表 --------------------编程问答-------------------- 1楼的最方便 --------------------编程问答-------------------- 新建1个MODEL包含ProductCategoryInfo(产品类型模型)(包含CategoryID, CategoryName)
ProductInfo(产品模型)全部内容。  
或者直接同时使用这两个模型。 --------------------编程问答-------------------- 新建一个 --------------------编程问答-------------------- 连接查询把得到的数据放到一个DataSet里面 然后再绑定 --------------------编程问答-------------------- 同意1楼的,但使用该实体获取数据的dal层,需要重写 --------------------编程问答--------------------
引用 1 楼  的回复:
 public class ProductInfo{

private ProductCategoryInfo  type;
 public ProductCategoryInfo Type
        {
            get { return type; }
            set { type= value; }
        }
}


那样的话,如果我大部分页面只需要绑定正常的ProductInfo,只有少部分页面绑定的ProductInfo包含ProductCategoryInfo信息, 那么大部分页面读出的数据都有冗余 --------------------编程问答--------------------
引用 5 楼  的回复:
新建1个MODEL包含ProductCategoryInfo(产品类型模型)(包含CategoryID, CategoryName)
ProductInfo(产品模型)全部内容。  
或者直接同时使用这两个模型。


那如果我功能需要其他模型的混合,2个或3个独立的模型联合起来,我都必须为他建一个新的模型吗?
同时使用2个模型,怎么可以2个同时联合起来绑定到GridView中呢? --------------------编程问答--------------------
引用 7 楼  的回复:
连接查询把得到的数据放到一个DataSet里面 然后再绑定


如果我使用DataTable作为数据容器的话,我何必去定义Model呢? --------------------编程问答-------------------- 笨方法 再写个类 里面的内容是你要的结果中那些字段和属性 --------------------编程问答-------------------- 哪位大牛有更好的方法呢? --------------------编程问答-------------------- 肯定要写语句进行组合查询的,如果非要使用集合的话,可以使用匿名类代替
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,