Reputation: 185
I am a new ASP.NET developer and I am trying to learn Linq-To-Entities. I am trying to create a static class called Items in my Data Access Layer. This class has a method to retrieve all the records in Items Entity. And then, I will use it for binding the GridView to it. The problem is that I got the following error in my getData() method when I make that class as a static class and I don't know why:
C# Code:
public static class Items
{
//properties
public int ID { get; set; }
public string Code { get; set; }
public int ItemTypeID { get; set; }
public string Name { get; set; }
public int StatusID { get; set; }
public static IEnumerable<Items> getData()
{
List<Items> itemsList = new List<Items>();
using (ItemsDBEntities context = new ItemsDBEntities())
{
itemsList = (from item in context.Items
select new Items()
{
ID = item.ID,
Code = item.Code,
Name = item.Name,
StatusID = item.StatusID
}).ToList();
}
return itemsList;
}
Could you please tell me how to fix this error?
Upvotes: 1
Views: 87
Reputation: 273514
Could you please tell me how to fix this error?
//public static class Items
public class Items
{
}
There are clear reasons why Items
should not be static
.
The getData()
method can remain static, although that doesn't seem necessary or useful either. It just makes testing a little harder. Do research state-management and the use of static in ASP.NET.
Id
and Name
properties is an Item
, not an Items
.GetData()
.Upvotes: 3