omaestra
omaestra

Reputation: 69

entity framework load only parent entity

I need to load an entity from Entity Framework(EF) but I only need the entity itself, I don't need any childs. I'm having troubles sending an object trought sockets because of the weight of the object.(Any suggestion about this?)

I'm using this code to get the list of objects I need:

…
private static DBEntities context = new DBEntities();
listaPlatos = context.PLATO.ToList();
…

My problem is that each object "PLATO" has others objects as childs. I want to ignore that childs and get only the "PLATO" entity.

Thanks.

Upvotes: 1

Views: 1052

Answers (2)

Mattias Åslund
Mattias Åslund

Reputation: 3907

Since you don't use an explicit loading of children, I guess lazy loading may cause you problems. Check out context.Configuration.LazyLoadingEnabled = false; Here is a relevant link: http://msdn.microsoft.com/en-us/data/jj574232.aspx

Upvotes: 2

Peter Kiss
Peter Kiss

Reputation: 9319

I think the problem is the serializer. A solution could be to use another class which is a pure POCO DTO class (this is always a best practise when you serializing something over the wire (sockets, WCF, whatever)).

var listaPlatos = context.PLATO.Select(x => new PlatoDto {
    Prop1 = x.SomeProp
});

Upvotes: 0

Related Questions