Tuesday, 27 August 2013

EF Repository not loading data from database

EF Repository not loading data from database

I have two databases that I need to call data from. IntranetApps and
LawOfficerServer (LORS).
The IntranetApps portion was written and is working. I'm adding the
LawOfficerServer portion.
I created and EDMX (LORSDataEntities.edmx) and two .tt files,
LORSDataEntities.Context.tt and LORSDataEntities.tt patterned after what
was working for IntranetApps. I created a separate Repository class,
LORSRepository.cs patterned after what was working.
All the Repository, EDMX, and .tt files are in a project called DataAccess.
I call for the data in the ServicesLayer project, which has my
LORSDataService.cs (patterned after what is working in the other side)
where I have a basic call to FindAll().
Here's the code:
public static List<Incident> GetAllIncidents()
{
using (IUnitOfWork unitOfWork = new LORSDataEntities())
{
LORSRepository<DataAccess.Models.LORS.Incident> incidentRepos
= new
LORSRepository<DataAccess.Models.LORS.Incident>(unitOfWork);
try
{
var incidents = incidentRepos.FindAll()
.Include(i => i.Officer);
.OrderBy(i => i.IncidentYear)
.ThenBy(i => i.Officer.BadgeNumber)
.ThenBy(i => i.IncidentNumber);
return incidents.ToList();
}
catch (InvalidOperationException exc)
{
ExceptionPolicy.HandleException(exc, "DataAccess");
throw exc;
}
}
}
Incident is a table in the EDMX. However I get this message:
The entity type Incident is not part of the model for the current context.
Using SQL Server Profiler, I can see the IntranetApps calls, but not the
LORS calls. It's as if the repository is never trying to talk to the
database.
In the web.config for the Web application I have this connectionString:
<add name="LORSDataEntities"
connectionString="metadata=res://*/Models.IntranetAppsEntities.csdl|res://*/Models.IntranetAppsEntities.ssdl|res://*/Models.IntranetAppsEntities.msl;provider=System.Data.SqlClient;provider
connection string=&quot;data source=FBHBGSQLDEV01;initial
catalog=LawOfficerServer;integrated security=False;User
Id=redacted;Password=xxxxxxx;multipleactiveresultsets=True;App=EntityFramework&quot;"
providerName="System.Data.EntityClient" />
Any thoughts where I went wrong, or to troubleshoot what I missed?

No comments:

Post a Comment