我使用实体框架并具有以下代码:
public class AdvPackageInfo
{
private int PackageId;
private string Caption;
private int Duration;
private int Count;
private bool Enable;
private float Price;
}
AdvertismentAgancyEntities enn = new AdvertismentAgancyEntities();
List<AdvPackageInfo> lst = (from s in enn.Tbl_AdvPackage select new AdvPackageInfo { }).ToList();
repeater1.DataSource = lst;
repeater1.DataBind();
但它只工作 1 次,当我的页面第二次加载时,它执行失败并引发 NullReferenceException ......!!
根据这个页面:
http
://connect.microsoft.com/VisualStudio/feedback/details/663200/linq-to-entities-throws-nullreferenceexception-when-the-output-attribute-set-is-empty
它是点网框架问题。
我也试试这个代码:
var q = (from s in enn.AdvPackage select s).toList();
但它也不起作用。
有没有更好的方法让 linq 选择列表????