If I write
var v = (from r in stock.ReplacementLog
select new
{
AssetId = stock.AssetId,
Date = stock.ReferDate,
FactType = r.Key,
Value = r.Value
});
It is working fine...
But if I do
IEnumerable<StockAsset> v = (from r in stock.ReplacementLog
select new {
AssetId = stock.AssetId,
Date = stock.ReferDate,
FactType = r.Key,
Value = r.Value });
I am getting error:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)
Then I did
IEnumerable<StockAsset> v =
(
from r in stock.ReplacementLog
select new
{
AssetId = stock.AssetId,
Date = stock.ReferDate,
FactType = r.Key,
Value = r.Value
}).ToList<StockAsset>();
With the following bunch of errors:
Error 1 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.IEnumerable'
Error 2 'System.Collections.Generic.IEnumerable' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable)' has some invalid arguments
Then I tried with
IEnumerable<StockAsset> v1 =
(from r in stock.ReplacementLog
select new StockAsset
{
AssetId = stock.AssetId,
ReferDate= stock.ReferDate,
FactType = r.Key,
Value = r.Value
});
with the errors: Error 1 'StockAsset' does not contain a definition for 'FactType'
**Error 2
'StockAsset' does not contain a definition for Value'**
The StockAsset Class is as under
public class StockAsset
{
public int AssetId { get; set; }
public DateTime ReferDate {get;set;}
public Dictionary<EnumFactorType, double> ReplacementLog { get; set; }
}
Need help.
Using C#3.0
Thanks