我创建了一个包含三个类作为属性的类:
public class Feeds
{
public Rentals Rentals { get; set; }
public Agent Agents { get; set; }
public NorthwindService.ServiceReference1.File File { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
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
};
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
无法使用集合初始值设定项初始化类型'NorthwindService.WebForm1.Feeds',因为它没有实现'System.Collections.IEnumerable'C:\ Users\NorthwindService\NorthwindService\WebForm1.aspx.cs
请建议解决方案
rem*_*rel 58
你在这里使用C#中的集合初始值设定项:
new myClass{a,b,c}
Run Code Online (Sandbox Code Playgroud)
其中myClass是一个集合,a,b,c将插入此集合中
您需要使用的表示法是对象初始值设定项
new myClass{
myProperty1 = a,
myProperty2 = b,
myProperty3 = c
}
Run Code Online (Sandbox Code Playgroud)
将初始化myClass的成员(或者您可能需要使用经典构造函数,然后使用括号更改括号)
new myClass(a,b,c)
Run Code Online (Sandbox Code Playgroud)
Pio*_*cik 42
应该:
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57096 次 |
| 最近记录: |