Reputation: 9194
Can I use the Entity Framework Model to allow me to create a list off of an existing table (entity)? If so I just can't figure out how to do that?
So for instance if I have a table in my DB called Order and that has been added to Entity Framework can I use the Entity Framework model to generate a List of Objects?
using SQL Server 2008 R2 and Visual Studio 2010
var orderContext = new OrderEntities();
var order = orderContext.Order;
List<order> ordersList = new List<order>();
That would be cool if I could.
Thanks,
S
Upvotes: 1
Views: 6052
Reputation: 222
"order" its a variable, you must create List for Type as:
List<Order> list = new List<Order>();
And then you can:
list = _context.Order.ToList();
(need using System.Linq)
Upvotes: 0
Reputation: 9298
Make sure that you are using System.Linq, you should be able to do the following. Presuming that Order is a ObjectSet.
using System.Linq;
Then use the ToList extension method.
IList<Order> orders = orderContext.Order.ToList();
Upvotes: 3