我正在學習作爲新手的「Visual Studio 2015社區」上的ASP.NET MVC 5。我試圖添加一個控制器與實體框架模型。添加控制器時無法檢索模型的元數據
,並出現了錯誤。我很困惑。
這裏是我的代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace TwiApp.Models
{
public class Twilio
{
[Key]
public int id { get; set; }
public string userId { get; set; }
public string sid { get; set; }
public string authToken { get; set; }
public string fromNumber { get; set; }
public string toNumber { get; set; }
public bool status { get; set; }
[ForeignKey("userId")]
public virtual ApplicationUser twi_appuser_ref { get; set; }
}
}
我的連接字符串到SQL Server 2014:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=TwiAppDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
最後,我databasecontext文件:
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;
using TwiApp.Models;
namespace TwiApp.DAL
{
public class DatabaseContext : IdentityDbContext<ApplicationUser>
{
public DatabaseContext() : base("DefaultConnection", throwIfV1Schema: false)
{
}
public DbSet<Twilio> Twilio_Db { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder);
}
public static DatabaseContext Create()
{
return new DatabaseContext();
}
}
}
我迄今爲止嘗試:
- ASP.NET MVC/EF Code First error: Unable to retrieve metadata for model
- Unable to retrieve metadata - MVC application
- Unable to Retrieve Metadata
- MVC4 Scaffolding Add Controller gives error "Unable to retrieve metadata..."
- Cannot create controller with Entity framework - Unable to retrieve metadata for ' '
任何答案將apprecited。謝謝。
您可能已經做到了這一點,但只是爲了安全起見。你有沒有嘗試重建項目,然後再次嘗試腳手架? – haseebahmed7
@ haseebahmed7是的,我已經嘗試重建和清潔項目,但它不工作! –
http://stackoverflow.com/questions/12546545/unable-to-retrieve-metadata –