Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 EF4 POCO Repository/UnitOfWork Connection Error

I implemented the T4 Repository/ Unit of Work templates by Gil Fink for use in a project I am working on, my first full scale project using MVC. I am, however, getting an error I wasn't getting before, and I can't track it down. I don't know if it's something with the templates, or just a setting somewhere I have set wrong, but I am at a lose right now. I was hoping someone would be able to shed some light on the situation.

Here's my framework setup:

  • MVC 3 Beta
  • SQL Server 2008 R2
  • Ninject v2.1.0.76
  • EF4 POCO
  • 3 projects in the solution: Data, Entities and the MVC app.

I am doing a DB first design, and using EF to create the POCO classes, via Microsoft's ADO.NET POCO Entity Generator. I then use the T4 tool to create the repository and unit of work patterns. With that setup, and all the classes and repositories generated, I implement it into the MVC app using Ninject for DI. I am using the MVC 2 method using a Controller Factory at this point, with plans to later change it to the IDependencyResolver method.

When I use a hard-coded Mock repository, the application works as it should, however when I change it to use the IRepository binding, I get the following error: "The supplied connection is not valid because it contains insufficient mapping or metadata information. Parameter name: connection" This indicates to me that the connection string for EF to connection to the DB is incorrect, however it is the default string generated by the ADO.NET Entity Data Model template. Perhaps it is also something with the .edmx settings.

Here is my connection string (using the handy Nerd Dinner database layout)

<add name="NerdDinnerEntities"
connectionString="metadata=
res://*/Model1.csdl|
res://*/Model1.ssdl|
res://*/Model1.msl;
provider=System.Data.SqlClient;
provider connection string=&quot;Data Source=Wayne;Initial Catalog=NerdDinner;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True&quot;"
providerName="System.Data.EntityClient" />

Anyone with any thoughts/ hints, etc, I would be extremely appreciative.

Edit: here's the link for the T4 template I'm using: Repository and Unit of Work T4 Template for Entity Framework

Edit2: The error is something to do with home I'm using DI with Unit Of Work. when I remove DI, and manually have the dependencies in the controllers, it works. When I try to implement DI, it breaks.

like image 236
Wayne W. Avatar asked Nov 01 '10 21:11

Wayne W.


1 Answers

res://*/Model1.csdl|

That * is a wildcard that says to EF "scan all the assemblies for the resource". Chances are this scan isn't finding the assembly for whatever reason.

Change * to your assembly name:

res://My.Assembly.Name/Model1.csdl|
like image 73
John Farrell Avatar answered Sep 26 '22 14:09

John Farrell