如何将表中的返回结果分配给通用列表
这是一种WCF服务方法。
public List<T> GetApprovedStateList(DateTime effectiveDate)
{
List<T> stateList = null;
using ( var db = new Context())
{
stateList = (from a in db.StateProductList
join b in db.States on a.stateID equals b.stateID
where a.effectiveDate <= effectiveDate
select b).ToList();
}
return stateList;
}
这是我的实体类
public class Entities
{
public class State
{
public int stateID { get; set; }
public string stateCode { get; set; }
public string stateDescription { get; set; }
}
这是我的背景
public class Context : DbContext, IDisposable
{
public Context() : base("EcommConnectionString")
{
}
public List<Entities.State> States { get; set; }
public List<Entities.Product> Products { get; set; }
public List<Entities.StateProduct_List> StateProductList { get; set; }
}
如何从WCF服务返回通用列表?
答案 0 :(得分:2)
您不会,因为您所没有的列表与该通用类型的类型不同。您应该返回实际值的类型列表。
public List<State> GetApprovedStateList(DateTime effectiveDate)
{
using ( var db = new Context())
{
return (from a in db.StateProductList
join b in db.States on a.stateID equals b.stateID
where a.effectiveDate <= effectiveDate
select b).ToList();
}
}