【发布时间】:2010-06-04 15:25:55
【问题描述】:
如果我写
var v = (from r in stock.ReplacementLog
select new
{
AssetId = stock.AssetId,
Date = stock.ReferDate,
FactType = r.Key,
Value = r.Value
});
一切正常……
如果我这样做了
IEnumerable<StockAsset> v = (from r in stock.ReplacementLog
select new {
AssetId = stock.AssetId,
Date = stock.ReferDate,
FactType = r.Key,
Value = r.Value });
我收到错误:
无法将类型“System.Collections.Generic.IEnumerable”隐式转换为“System.Collections.Generic.IEnumerable”。存在显式转换(您是否缺少演员表?)
然后我做了
IEnumerable<StockAsset> v =
(
from r in stock.ReplacementLog
select new
{
AssetId = stock.AssetId,
Date = stock.ReferDate,
FactType = r.Key,
Value = r.Value
}).ToList<StockAsset>();
出现以下一堆错误:
错误 1 实例参数:无法从 'System.Collections.Generic.IEnumerable' 转换为 'System.Collections.Generic.IEnumerable'
错误 2“System.Collections.Generic.IEnumerable”不包含“ToList”的定义和最佳扩展方法重载“System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable)”有一些无效的参数
然后我尝试了
IEnumerable<StockAsset> v1 =
(from r in stock.ReplacementLog
select new StockAsset
{
AssetId = stock.AssetId,
ReferDate= stock.ReferDate,
FactType = r.Key,
Value = r.Value
});
有错误: 错误 1 “StockAsset”不包含“FactType”的定义
**Error 2
'StockAsset' does not contain a definition for Value'**
StockAsset 类如下
public class StockAsset
{
public int AssetId { get; set; }
public DateTime ReferDate {get;set;}
public Dictionary<EnumFactorType, double> ReplacementLog { get; set; }
}
需要帮助。
使用 C#3.0
谢谢
【问题讨论】:
标签: linq c#-3.0 anonymous-types