I am trying to learn singleton pattern but had some issues with getting datas from a table and populate my gridview. Btw I am using entity framework.
Here is my gridview:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
My PersonelTable Class:
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; }
}
My userbusiness class:
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;
}
}
And lastly codebehind of my webform:
protected void PopulateGridView()
{
List<PersonelTable> personelList = UserBusiness.Instance.GetAllUsers();
GridView1.DataSource = personelList;
GridView1.DataBind();
}
I get an error like 'ProjectName.PersonelTable hasn't got creator without parameter' in the foreach of my 'GetAllUsers' method. Why is this happening and how can I fix it ?