Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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
Linq to sql P在C#表达式中是什么意思?_Linq To Sql_Sorting_Data Binding_Binding_Entityset - Fatal编程技术网

Linq to sql P在C#表达式中是什么意思?

Linq to sql P在C#表达式中是什么意思?,linq-to-sql,sorting,data-binding,binding,entityset,Linq To Sql,Sorting,Data Binding,Binding,Entityset,我试图使用post中的答案:公开一个接口,这样我就可以用绑定列表对EntitySet进行排序。我已经创建了下面的类,但出现了以下编译器错误:“找不到类型或命名空间‘P’(是否缺少using指令或程序集引用?)。有人能告诉我P的意思吗?我需要包含哪个命名空间才能编译下面的方法?我对委托和lamba表达式非常陌生 另外,是否有人可以确认,如果我从EntitySet创建BindingList,那么我对BindingList所做的任何修改都将对EntitySet进行 基本上,我有一个EntitySet,

我试图使用post中的答案:公开一个接口,这样我就可以用绑定列表对EntitySet进行排序。我已经创建了下面的类,但出现了以下编译器错误:“找不到类型或命名空间‘P’(是否缺少using指令或程序集引用?)。有人能告诉我P的意思吗?我需要包含哪个命名空间才能编译下面的方法?我对委托和lamba表达式非常陌生

另外,是否有人可以确认,如果我从EntitySet创建BindingList,那么我对BindingList所做的任何修改都将对EntitySet进行

基本上,我有一个EntitySet,需要对其进行排序和更改。然后,我需要使用BindingList来自的原始实体来持久化这些更改

public class EntitySetBindingWrapper<T> : BindingList<T>
{
    public EntitySetBindingWrapper(BindingList<T> root)
        : base(root)
    {
    }

            public void Sort<P>(Expression<Func<T, P>> expr, ListSortDirection direction)
    {
        if (expr == null)
            base.RemoveSortCore();

        MemberExpression propExpr = expr as MemberExpression;
        if (propExpr == null) throw new ArgumentException("You must provide a property", "expr");

        PropertyDescriptorCollection descriptorCol = TypeDescriptor.GetProperties(typeof(T));
        IEnumerable<PropertyDescriptor> descriptors = descriptorCol.Cast<PropertyDescriptor>();
        PropertyDescriptor descriptor = descriptors.First(pd => pd.Name == propExpr.Member.Name);

        base.ApplySortCore(descriptor, direction);
    }
}

有人能告诉我如何调用此构造函数并确认如何对生成的BindingList进行排序吗?

您需要在类定义或方法定义中指定泛型变量

p
将是函数返回的类型
expr

public void Sort<P>(Expression<Func<T, P>> expr, ListSortDirection direction)
公共无效排序

(表达式表达式表达式,列表排序方向)


对于调用构造函数,以下操作可以正常工作:

var w=new EntitySetBindingWrapper(new System.ComponentModel.BindingList());


您在
currentPredefinedJob.fkItems.GetNewBindingList()中所做的工作是否可能出现问题

好的,我想我理解了关于p是返回类型的部分。但是,我甚至无法在方法签名中使用p来编译类。是否有我缺少的名称空间?到目前为止,我已经包含了:System.Linq.Expressions、System.Linq.Data和System.Linq。一旦我清理了项目并重新编译,我就能够解析这个错误,但是,现在我在尝试实例化列表时又遇到了一次。你介意看看我在修改后的帖子中的代码示例和相应的错误吗?@Grasshopper-你没有修改方法定义以包含
P
?我确实修改了方法,但现在我无法找到调用constr的正确语法uctor.@Grasshopper-如果你更新了你的代码,你应该用正确的方法定义更新你的问题
var bindingWrapper = new EntitySetBindingWrapper(currentPredefinedJob.fkItems.GetNewBindingList());
public void Sort<P>(Expression<Func<T, P>> expr, ListSortDirection direction)