Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

c# - Add controller error unable to retrieve metadata

I want to add controller in my MVC 4 application in VS2012 as this image:

add controller

Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MvcDemo.Models
{
    public class MovieDB
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Director { get; set; }
        public DateTime Date { get; set; }
    }
    public class MovieDBContext : DbContext
    {
        public DbSet<MovieDB> Movies { get; set; }
    }
}

Connection strings:

<connectionStrings>

<add name="DefaultConnection" 
connectionString="Data Source=(LocalDb)v11.0;Initial Catalog=aspnet-MvcDemo-20130315191956;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnet-MvcDemo-20130315191956.mdf"
providerName="System.Data.SqlClient" />

<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>

</connectionStrings>

After clicking "add", this error occurs:

unable to retrieve metadata for 'MvcDDemo.Models.MovieDB'.Using the
same DbCompiledModel to create contexts against different type of
database servers is not supported.instead,create a 
separate DbCompiledModel for each type of server being used.

Any suggestion?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Web.config, set second providerName same as first providerName, and after creating controller, undo that!

from:here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...