Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework ';通用';视图模型_Entity Framework_Mvvm_Repository_Generics_Entity Framework 4 - Fatal编程技术网

Entity framework ';通用';视图模型

Entity framework ';通用';视图模型,entity-framework,mvvm,repository,generics,entity-framework-4,Entity Framework,Mvvm,Repository,Generics,Entity Framework 4,使用EF4,我有几个“业务”实体的子类型(客户、供应商、运输公司等)。它们确实需要是子类型。我正在构建一个通用的viewmodel,它调用一个服务,从该服务访问一个通用的存储库 因为我有4个子类型,所以最好将“通用”viewmodel用于所有这些类型。当然,问题是我必须将特定类型调用到我的通用存储库中,例如: BusinessToRetrieve = _repository .LoadEntity<Customer>(o => o.CustomerID == custo

使用EF4,我有几个“业务”实体的子类型(客户、供应商、运输公司等)。它们确实需要是子类型。我正在构建一个通用的viewmodel,它调用一个服务,从该服务访问一个通用的存储库

因为我有4个子类型,所以最好将“通用”viewmodel用于所有这些类型。当然,问题是我必须将特定类型调用到我的通用存储库中,例如:

BusinessToRetrieve = _repository
    .LoadEntity<Customer>(o => o.CustomerID == customerID);
BusinessToRetrieve=\u存储库
.LoadEntity(o=>o.CustomerID==CustomerID);

如果能够调用
,这将是一件好事,有些东西可能是一种或另一种子类型),否则我将不得不创建4个几乎相同的VIE模型,这当然是一种浪费!viewmodel可以使用子类型实体名称,但我无法确定如何使上面的调用将其转换为类型。实现我想要的目标的一个问题是,可能传入的lambda表达式无法在“通用”调用中解析?

听起来您需要熟悉它。首先,您将能够编写如下代码:

class ViewModel<T> where T : Business {
    public void DoSomething(Func<T, bool> predicate) {
        BusinessToRetreive = _repository.LoadEntity<T>(predicate);
    }
}
类视图模型,其中T:Business{
公共void DoSomething(Func谓词){
BusinessToRetree=\u repository.LoadEntity(谓词);
}
}
然后你可以说:

ViewModel<Customer> c = new ViewModel<Customer>();
c.DoSomething(o => o.CustomerID == customerID);
ViewModel c=newviewmodel();
c、 DoSomething(o=>o.CustomerID==CustomerID);

听起来你需要让自己熟悉。首先,您将能够编写如下代码:

class ViewModel<T> where T : Business {
    public void DoSomething(Func<T, bool> predicate) {
        BusinessToRetreive = _repository.LoadEntity<T>(predicate);
    }
}
类视图模型,其中T:Business{
公共void DoSomething(Func谓词){
BusinessToRetree=\u repository.LoadEntity(谓词);
}
}
然后你可以说:

ViewModel<Customer> c = new ViewModel<Customer>();
c.DoSomething(o => o.CustomerID == customerID);
ViewModel c=newviewmodel();
c、 DoSomething(o=>o.CustomerID==CustomerID);

我不确定这是否是您想要的,但您可能会感兴趣


我不确定这是否是你想要的,但你可能会感兴趣