views:

94

answers:

1

Hi

I want to develop an ASP.Net MVC application with EF4 Model First design and only generate the actual database much later, ideally at the end of the project.

Based on some of the ideas here:

http://elegantcode.com/2009/12/15/entity-framework-ef4-generic-repository-and-unit-of-work-prototype/

I want to create something like an InMemoryObjectContext for testing and development and use IOC to switch to the SQL Server implamentation (EF generated) for UAT and production.

Is this wise?

Is it possible? If so, does anyone have any suggestions?

Does EF always need an underlying database in order to track changes, commit etc?

I've tried creating a model first but as soon as I add properties I get the following errors:

Error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer Model1Container.

and the warning:

Running transformation: Please overwrite the replacement token '$edmxInputFile$' with the actual name of the .edmx file you would like to generate from.

The error doesn't stop the application running but worries me. I'm very very new to EF so I apologize if this is way off the mark or a dumb question. I'm hoping to get some good advice while I sit for the next few days and watch videos and read articles.

Thanks

Davy

+1  A: 

At the very least you need mapping information "filled in". You can fill these fields with nonsense if you don't want to work against the underlying database.

If your doing Model first, right click on the designer canvas and select, "Generate Database from Model". This will automatically create convention based mappings for you without defining tables and columns. You don't even need a valid db connection to do this.

jfar
Thanks, I tried this and it works to a degree, but if I try to do anything with my context such:Model1Container context = new Model1Container(); context.Employees.AddObject(e); var i = context.Employees.Count(); I get Invalid object name 'dbo.Employees'.
Davy
I have to run the generated script in sql server, creating the physical table. Is this what you meant. Thanks.
Davy