I am using Entity frame work in my asp.net MVC 4 application. I have an edmx file. I am trying to use the entity from this EF model to populate a viewmodel like this:
using (var context = new VehiclesContext())
{
IEnumerable<SearchedVehicles> vehicles = context.Vehicles.Select(x => new SearchedVehicles
{
Year = x.Year,
Make = x.Make,
Model = x.Model,
Mileage = x.Mileage,
VIN = x.VIN
});
return View(vehicles);
}
Vehicles is entity in edmx where SearchedVehicles is viewmodel but I get this exception:
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
on this line:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}