Unable to generate Controller for Entity using SqlServer CE 4.0: ScaffoldingConnectionFactory Error

704 Views Asked by At

I am getting the feel of SqlServer CE 4.0 to use with MVC 3 without installation. Things are going fine. I have successfully integrated Troy Goode's MembershipStarterKit and also ErikEJ's SqlServerCEMembership provider. Both are working find. Now I have a moder class:

public class Student
{
    [Key]
    public int Id{get;set;}
    [Required]
    public string FirstName{get;set;}
    [Required]
    public string LastName{get;set;}
    [Required]
    public DateTime DOB{get;set;}
    [Required]
    public string Gender{get;set;}
}

I am also using DBContext class:

public class MyDbContext: DBContext
{
    public DbSet<Student> Students{get;set;}
}

When I try to add a controller by selecting the Student class as model, I am getting the following error:

Unable to retrieve metadata for 'MVCProject1.Models.Student'. There was an error 
generating 'ScaffoldingConnectionFactory. Try Rebuilding your project.

I have tried both 4.3.0 and 4.3.2 versions of package EntityFrameWork.SqlServerCompact but am still getting the error. What is wrong with my approach?

EDIT:- I have tried again and again after rebuilding the project, by uninstalling/re-installing packages.

1

There are 1 best solutions below

0
On

Well it turned out to be a matter of confused extensions. I had installed EntityFramework and EFCodeFirst, EFCodeFirst.SqlServerCompact. This seemed to cause problem. I uninstalled EFCodeFirst, EFCodeFirst.SqlServerCompact including dependencies and then EntityFramework also.

Clean installing EntityFramework, EntityFramework.SqlServerCompact resolved the issue.