0

I am following Steven Sanderson's "Pro ASP.Net MVC2 Framewok", which uses Linq2SQL. He uses abstract factory approach to support unit testing and mocking, and writes model classes in a separate project to facilitate this.

I am using Linq to Entity Framework instead of Linq2SQL, and I have built an entity model in EF from an existing database. (I am new to all of this).

I don't quite understand if I'm getting this right, but I beleive I should still generate model classes defined outside of EF (a layer between EF and presentation?), even though I could just pass Linq2EF query results entities directly in as MVC's models (security? separation of concerns?).

So I'd like EF to stub the model classes for me instead of hand-coding them all from scratch. Is there an easy way to do this, or am I mis-interpreting what I need to do?

2
  • EF will build an entire object graph for you. You will end up with one Container class that should expose all the "tables" to you. You can then create an instance of the Container and query the tables with LINQ. If you need to extend any of the model classes, you just create new partial classes. This saves work when regenerating the EF model. Commented Apr 8, 2011 at 13:45
  • @tomasmcguinness: Yes, this part I get. However, from what I'm reading, just using the EF entities directly this way, as MVC's models, is not a proper separation of concerns, and I won't be able to do unit-testing very easily. If you read the blog-post that Csharper references, you'll see what I'm talking about. Commented Apr 9, 2011 at 23:31

1 Answer 1

1

Take a look at this blog great resource on this subject.

If you are going to use ViewModels I highly recomend using AutoMapper from souceforge

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

1 Comment

Thanks. I have not been able to find any documentation for AutoMapper -- could you point me to something?

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.