本文介绍了添加控制器错误无法检索元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VS2012的MVC 4应用程序中添加控制器,如下图所示:





模型:

  c>  ,第二个 providerName  providerName ,然后创建控制器,撤消该操作!



from:


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

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?

解决方案

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

from:here

这篇关于添加控制器错误无法检索元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 16:33