0

I'm building a WPF application, and I'm using a WebService to retrieve data from Database using Entity Framework. On my service the code generated is:

public partial class DummyEntities : ObjectContext
    {
        public DummyEntities() : base("name=DummyEntities", "DummyEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

//more 2 constructors with diferent signature but the same code

So the Lazy Loading option is enabled.

The problem is on the app side, when I do something like this:

DummyEntities context = new DummyEntities(Utils.GetUri());
//            ...
context.Order.Order_Details.Count

give me count = 0, when it shouldn't because Lazy loading is active. Am I missing something here?

2

2 Answers 2

2

If you've crossed a service boundary, the entities have been serialized and deserialized to another object, so they've lost the connection to the db

All lazy loading has to be done before the data is transferred

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks for the hint Daniel. I searched a little more and I found the LoadProprety method. That solves the problem. Thanks

Edit:

The code I used was:

IEnumerable<Order> orders = context.Order.AsEnumerable<Order>();

        foreach (var order in orders)
        {
            context.LoadProperty(order, "Order_Details");
            result.Add(new Order(order));
        }

This way I'm forcing each order to load the "Order_Details" related entity

1 Comment

Could you explain how it solved the problem? What did you change in order to get it to work?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.