绑定匿名类型创建的BindingList [英] Binding anonymous type to Create a BindingList

查看:187
本文介绍了绑定匿名类型创建的BindingList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个的BindingList<由LINQ查询,但的BindingList<返回的匿名类型>;>不接受匿名类型,下面是我的代码



  VAR数据= context.RechargeLogs.Where(T => t.Time> = DateTime.Today)。 
选择(T =>新建
{
COL1 = t.Id,
COL2 = t.Compnay,
COL3 = t.SubscriptionNo,
COL4 = t.Amount,
COL5 = t.Time
});

变种TMP =新的BindingList< ???>(数据);

在最后一行一般的参数的地方是什么?


< DIV CLASS =h2_lin>解决方案

您可以写一个扩展方法:

 静态类MyExtensions 
{
公共静态的BindingList< T> ToBindingList< T>(这个IList的< T>源)
{
返回新的BindingList< T>(源);
}
}

和使用这样的:

  VAR的查询=实体
。选择(E =>新建
{
//这里构造匿名实体
})
.ToList()
.ToBindingList();


I am trying to create a BindingList<> from anonymous type returned by LINQ query but BindingList<> do not accept anonymous type, following is my code

var data = context.RechargeLogs.Where(t => t.Time >= DateTime.Today).
           Select(t => new 
           {
                col1 = t.Id,
                col2 = t.Compnay,
                col3 = t.SubscriptionNo,
                col4 = t.Amount,
                col5 = t.Time
           });

var tmp =  new BindingList<???>(data);

In the last line generic argument what to place ???

解决方案

You can write an extension method:

static class MyExtensions
{
    public static BindingList<T> ToBindingList<T>(this IList<T> source)
    {
        return new BindingList<T>(source);
    }
}

and use it like this:

        var query = entities
            .Select(e => new
            {
               // construct anonymous entity here
            })
            .ToList()
            .ToBindingList();

这篇关于绑定匿名类型创建的BindingList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆