1

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

1
  • Your question is not clear enough for me. Are you asking to retrieve rows out of the database as entity objects? Commented Dec 9, 2011 at 0:33

2 Answers 2

3

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();
Sign up to request clarification or add additional context in comments.

Comments

0

"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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.