1

I'm attempting to setup Entity Framework using Code First on an existing database. The database isnt in great shape (poor naming convention and some constraints are needed). The application I'm building is an MVC app. I have a "Model", "Repository", and "Web" (mvc) tiers.

To setup EF and map my model objects (POCO objects), is it required that I match my objects to database tables? Can I, instead, use my own stored procedures for CRUD operations? Would it help if I use WCF data services?

I'm planning on using fluent configurations to map my objects, but having some issues due to the database schema. I'm know considering redesigning the database just to get EF to map correctly. Any suggestions would be greatly appreciated!!

Nathan Hall
  • 409
  • 2
  • 8
  • 17
  • possible duplicate of [Does Entity Framework Code First support stored procedures?](http://stackoverflow.com/questions/4845246/does-entity-framework-code-first-support-stored-procedures) – Erik Funkenbusch Sep 14 '12 at 18:53

2 Answers2

1

Looks awfully similar to this question:

Does Entity Framework Code First support stored procedures?

The answers there may be helpful to you, as well as the discussion surrounding how Code First and Stored Procedures don't make a whole lot of sense.

Wow, Julie Lerman answered!

Community
  • 1
  • 1
vbullinger
  • 4,016
  • 3
  • 27
  • 32
0

Yes, it's possible, but not particularly easy. In particular, you must call context.Database.SqlQuery<T>() where T is the entity type you want to return, and your SQL must match up to that entity type. Otherwise, you will have to massage a result set into a type.

In general, you will have to do most of this manually, although you could probably figure out a T4 template to generate it for you, or maybe use some other tool like CodeSmith.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291