3

Lets say we are using DTO objects to transfer data between service layer and Presentation (MVC) layer.In this case the presentation layer can only access DTO objects. Therefore we can't use lazy loading functionality in Entity framework. Am I right here? Please give your suggestions.

(My DTO are not the entities in EF and I have implemented repository and unit of work pattern)

2 Answers 2

2

You can use lazy loading but only on your service side when you are working with attached entities.

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

2 Comments

So then, Is it good to have DTO pattern with entity framework? because we need to load navigational properties using'Include' method?
If you know upfront that you will pass data to DTO you should avoid lazy loading because it can result in many unnecessary database roundtrips.
1

First put your definition right: Are your DTO objects also your entities in EF 4.1? Are they (also) your models and do they contain business logic?

If so, i would recommend turning off proxy creation ( myDbContext.Configuration.ProxyCreationEnabled = false; ) since they cant be serialized easily. Then use a repository for dataAccess where in the CRUD methods, you specify the right entity states like: http://blogs.msdn.com/b/adonet/archive/2011/01/29/using-dbcontext-in-ef-feature-ctp5-part-4-add-attach-and-entity-states.aspx

1 Comment

My DTO are not the entities in EF and I have implemented repository and unit of work pattern

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.