我正在尝试学习单例模式,但是从表中获取数据并填充我的gridview时遇到了一些问题。顺便说一下,我正在使用实体框架。
这是我的gridview:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
我的PersonelTable类:
public class PersonelTable
{
public PersonelTable(string isim,string soyad)
{
Isim = isim;
Soyad = soyad;
}
public int Id { get; private set; }
public string Isim { get; set; }
public string Soyad { get; set; }
}
我的用户业务类:
public sealed class UserBusiness
{
private JuqueryDbEntities entity = new JuqueryDbEntities();
private static volatile UserBusiness instance;
private static readonly object syncRoot = new Object();
private UserBusiness() { }
public static UserBusiness Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new UserBusiness();
}
}
return instance;
}
}
public List<PersonelTable> GetAllUsers()
{
List<PersonelTable> personelList = new List<PersonelTable>();
var users = (from u in entity.PersonelTable select u);
foreach (var user in users)
{
personelList.Add(new PersonelTable(user.Isim,user.Soyad));
}
return personelList;
}
}
最后是我的webform的代码隐藏:
protected void PopulateGridView()
{
List<PersonelTable> personelList = UserBusiness.Instance.GetAllUsers();
GridView1.DataSource = personelList;
GridView1.DataBind();
}
我收到错误,例如&#39; ProjectName.PersonelTable没有参数&#39;在我的&#39; GetAllUsers&#39;的foreach中方法。为什么会发生这种情况?我该如何解决?
答案 0 :(得分:0)
我认为你在Person表中传递的参数确实是不需要的。你可以删除那个参数再试一次吗?