【发布时间】:2012-09-02 15:07:59
【问题描述】:
我有这个架构:
------(WPF APPLICATION)(XAML,ViewModels)(知道业务逻辑但不知道 DAL)
------(类库)(业务逻辑)(了解 DAL)
-----(类库)(DAL - 实体框架(模型优先))(不参考任何人)
我的问题是我的 DAL 不知道任何业务逻辑类 所以在我的 DAL 中,如果我得到一个比如说一个人的列表,我会返回 IEnumerable。 例如:
public static IEnumerable GetPersons()
{
using(StaffEntities context = new StaffEntities())
{
return context.Persons.ToList();
}
}
所以当我从业务逻辑层得到结果时,我有一个对应的类 每个实体都说 DAL 中的 Person Entity,我在业务逻辑层中有 clsPerson。 但我的视图模型不知道 DAL,它只知道业务逻辑类,因此 clsPerson 所以我的业务逻辑中的代码变成了
例如:
public static IEnumerable GetclsPersons()
{ return DAL.GetPersons(); }
我的大问题是每次我得到一个列表时,保存或删除一些东西 我必须在我的 ViewModel 中使用反射
所以如果我有一个 clsPerson 属性绑定到我的 xaml:
public IEnumerable clsPersons { get; set; }
public ListCollectionView clsPersonList { get; set; }
clsPersons = BLL.GetclsPersons();
clsPersonList = new ListCollectionView((IList)clsPersons);
public clsPerson CurrentclsPerson { get; set; }
每次我为“CurrentclsPerson”赋值时,我都必须使用反射
CurrentclsPerson.Firstname = clsPersonList.CurrentItem.GetType().GetProperty("Firstname")
.GetValue(clsPersonList.CurrentItem,null).ToString();
我希望不在我的视图模型中使用反射 我正在考虑将我的业务逻辑和 DAL 放在一个类库中,这样我就不会 必须使用 IEnumerable
你们都用什么?
有没有办法避免这种情况?
这里面还有吗?
请帮忙..谢谢。
【问题讨论】:
标签: c# wpf entity-framework mvvm business-logic