public object selecta() { var query = from A in Context.AccidentMsg join B in Context.PeopleMessage on A.AccID equals B.AccID join C in Context.SysDictionary on A.DealWayID equals C.ID //join D in Context.PoliceMan on A.PoliceNo equals D.PoliceNo join E in Context.SysDictionary on B.Responsibility equals E.ID select new { A.AccidentNo, A.Time, A.Place, B.Name, B.Sex, B.PeopleAge, B.CertificateNo, B.TrafficTypeID, B.PhoneNo, B.CarNo, B.LostMoney, B.IsDead, Ename = E.Name, A.PoliceNo, //警员编号->->->警员姓名 Cname = C.Name, A.DeptID }; return query.ToList(); }
我对selecta 进行遍历,提示selecta中不包含GetEnumerator公共定义
像这种情况应该怎么解决,求方案,求代码
这新人也忒新了。。。
算是自学的
@逆风的刃: 你把返回值改成强类型,List<>
linq里面别匿名。。。
。。。。
你selecta() 的返回类型应该是一个List<T>()才对吧?.
不行,试过了
@逆风的刃:
.. 你自己弄一个类啊.~. 用List<T>() 当返回值.
@逆风的刃:
假设你的类是这样.
public class Test { public string AccidentNo; public string Time; public string Name; public string Sex; public string PeopleAge; public string CertificateNo; public string TrafficTypeID; public string PhoneNo; public string CarNo; public string LostMoney; public string IsDead; public string EName; public string PoliceNo; public string Cname; public string DeptID; }
那么你的selecta()应该是这样
public List<Test> selecta() { var query = from A in Context.AccidentMsg join B in Context.PeopleMessage on A.AccID equals B.AccID join C in Context.SysDictionary on A.DealWayID equals C.ID //join D in Context.PoliceMan on A.PoliceNo equals D.PoliceNo join E in Context.SysDictionary on B.Responsibility equals E.ID select new Test { AccidentNo=A.AccidentNo, Time=A.Time, Place=A.Place, Name=B.Name, Sex=B.Sex, PeopleAge=B.PeopleAge, CertificateNo=B.CertificateNo, TrafficTypeID=B.TrafficTypeID, PhoneNo=B.PhoneNo, CarNo=B.CarNo, LostMoney=B.LostMoney, IsDead=B.IsDead, Ename = E.Name, PoliceNo=A.PoliceNo, //警员编号->->->警员姓名 Cname = C.Name, DeptID=A.DeptID }; return query.ToList(); }
@李丶GuanYao: 匿名的也可以,错误不在此处
@jello chen: 不好意思,刚没仔细看,看了下,selecta()这个居然返回的是object
@jello chen:
主要错误不是在Object返回型吗.
他想Foreach. Object类型的怎么Foreach.
@李丶GuanYao: 嗯,如果真要这样的话,只需将var query=new AcciDA().selecta();改成dynamic query=new AcciDA().selecta();就好
@jello chen:
应该是要把方法的返回类型改成
public dynamic selecta() 或者 public IList selecta()
@李丶GuanYao: 改成public dynamic selecta()可以,改成public IList selecta()依然得改成这样
foreach(dynamic data in query)才行吧
@jello chen:
嗯. 你说的很对.. 用public dynamic selecta() 最简单
@李丶GuanYao: 你那就不是泛型好么???
@顾晓北:
...不好意思.. 是实体类..
写上一个类,让其实现IEnumerable接口,且实现里面的GetEnumerator方法,就行,
顶楼上 http://blog.csdn.net/byondocean/article/details/6871881