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
C# 如何从entitydatasource绑定到detailsview获取返回的实体?_C#_Entity Framework_Entitydatasource - Fatal编程技术网

C# 如何从entitydatasource绑定到detailsview获取返回的实体?

C# 如何从entitydatasource绑定到detailsview获取返回的实体?,c#,entity-framework,entitydatasource,C#,Entity Framework,Entitydatasource,我试图在数据源的Selected事件中获取实体,如下所示 protected void edsRetailer_OnSelected(object sender, EntityDataSourceSelectedEventArgs e) { if(e.Results == null) return; var list = (IEnumerable<Retailer>) e.Results; } 我尝试将其强制转换为ObjectView,但在我尝试强制转换时,该类似

我试图在数据源的
Selected
事件中获取实体,如下所示

protected void edsRetailer_OnSelected(object sender, EntityDataSourceSelectedEventArgs e)
{
    if(e.Results == null) return;
    var list =  (IEnumerable<Retailer>) e.Results;
}

我尝试将其强制转换为
ObjectView
,但在我尝试强制转换时,该类似乎不存在。

您不必将
e.Results
强制转换为
ObjectView
,因为这已经是返回类型。(此外,
System.Data.Objects.ObjectView
是一个内部类)。但关键是它实现了
IEnumerable
(作为
IBindingList
的一部分),而不是
IEnumerable

将非泛型IEnumerable转换为泛型IEnumerable的常用方法是:

var list=e.Results.Cast();

您不必将
e.Results
转换为
ObjectView
,因为这已经是返回类型。(此外,
System.Data.Objects.ObjectView
是一个内部类)。但关键是它实现了
IEnumerable
(作为
IBindingList
的一部分),而不是
IEnumerable

将非泛型IEnumerable转换为泛型IEnumerable的常用方法是:

var list=e.Results.Cast();
Unable to cast object of type 'System.Data.Objects.ObjectView`1[CCBusiness.Retailer]' to type 'System.Collections.Generic.IEnumerable`1[CCBusiness.Retailer]'
var list =  e.Results.Cast<Retailer>();