将IQueryable转换为DataRowView

时间:2011-08-09 03:49:08

标签: c# linq

我有一个绑定源,它以LINQ to SQL的IQueryable结果为界。

private void loadProducts(short _engineID)
{    
     dbLinqDataContext db = new dbLinqDataContext();                   
     var  productQuery = from pe in db.productEngines
                         where pe.EngineID == _engineID
                         select new
                         {
                           ProductID = pe.ProductID,
                           ProductNumber = pe.product.ProductNumber,
                           Description = pe.product.ProductName,
                           Cost = String.Format("{0:C}", pe.product.StandardCost),
                           Price = String.Format("{0:C}", pe.product.ListPrice),
                           QOH = String.Format("{0:0.00}",pe.product.QOH),
                           Picture = pe.product.Picture,
                           Category =pe.product.category.Category1,   

                           Engine=pe.engine.ModelSeriesYear,
                           Manufacturer=pe.engine.manufacturer.Manufacturer
                        };

productQueryBindingSource.DataSource = productQuery;     }

然后我无法将我的bindingsource当前项转换为DataViewRow。

DataRow currentRow = ((DataRowView)productQueryBindingSource.Current).Row;

如何将我的匿名类型转换为DataViewRow类型?

1 个答案:

答案 0 :(得分:0)

将Anonymous转换为DataRow,应该使用反射。有关详细信息,请查看以下链接

Converting Custom Collections To and From DataTable