无法使用集合初始化程序初始化类型“",因为它未实现"System.Collections.IEnumerable" [英] Cannot initialize type '' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
本文介绍了无法使用集合初始化程序初始化类型“",因为它未实现"System.Collections.IEnumerable"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个类,其中包含三个类作为属性:
I have created a class which holds three classes as properties:
public class Feeds
{
public Rentals Rentals { get; set; }
public Agent Agents { get; set; }
public NorthwindService.ServiceReference1.File File { get; set; }
}
我正在这样使用它:
var query = from r in ent.Rentals
join a in ent.Agents on r.ListingAgentID equals a.AgentID
select new Feeds
{
a.AgentID,
a.Alias,
a.Bio,
a.Email,
a.Fax,
r.Firstname,
r.IsStaff,
r.Languages
};
但是我得到了错误:
无法使用集合初始化程序初始化类型'NorthwindService.WebForm1.Feeds',因为它没有实现'System.Collections.IEnumerable'C:\ Users \ NorthwindService \ NorthwindService \ WebForm1.aspx.cs
Cannot initialize type 'NorthwindService.WebForm1.Feeds' with a collection initializer because it does not implement 'System.Collections.IEnumerable' C:\Users\NorthwindService\NorthwindService\WebForm1.aspx.cs
请提出解决方案.
推荐答案
应为:
var query = from r in ent.Rentals
join a in ent.Agents on r.ListingAgentID equals a.AgentID
select new Feeds
{
Agents = a,
Rentals = r
}
这篇关于无法使用集合初始化程序初始化类型“",因为它未实现"System.Collections.IEnumerable"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文