我首先使用代码第一个数据库(MYSQL,ENTITYFRAMEWORK 6,VISUAL STUDIO 2015) 我正在尝试使用生成的模型中的脚手架添加控制器
但我得到"运行所选代码生成器序列时出错,不包含任何元素,无法检索...的元数据;序列不包含匹配元素&#34 ;;
模型是从数据库中成功生成的,但是使用scaffolding为指定模型添加控制器会返回错误。
DataContex
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
public partial class Model1 : DbContext
{
public Model1()
: base("name=Model1")
{
}
public virtual DbSet<actor> actors { get; set; }
public virtual DbSet<address> addresses { get; set; }
public virtual DbSet<category> categories { get; set; }
public virtual DbSet<city> cities { get; set; }
public virtual DbSet<country> countries { get; set; }
public virtual DbSet<customer> customers { get; set; }
public virtual DbSet<film> films { get; set; }
public virtual DbSet<film_actor> film_actor { get; set; }
public virtual DbSet<film_category> film_category { get; set; }
public virtual DbSet<film_text> film_text { get; set; }
public virtual DbSet<inventory> inventories { get; set; }
public virtual DbSet<language> languages { get; set; }
public virtual DbSet<payment> payments { get; set; }
public virtual DbSet<rental> rentals { get; set; }
public virtual DbSet<staff> staffs { get; set; }
public virtual DbSet<store> stores { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<actor>()
.Property(e => e.first_name)
.IsUnicode(false);
modelBuilder.Entity<actor>()
.Property(e => e.last_name)
.IsUnicode(false);
modelBuilder.Entity<actor>()
.HasMany(e => e.film_actor)
.WithRequired(e => e.actor)
.WillCascadeOnDelete(false);
modelBuilder.Entity<address>()
.Property(e => e.address1)
.IsUnicode(false);
modelBuilder.Entity<address>()
.Property(e => e.address2)
.IsUnicode(false);
modelBuilder.Entity<address>()
.Property(e => e.district)
.IsUnicode(false);
modelBuilder.Entity<address>()
.Property(e => e.postal_code)
.IsUnicode(false);
modelBuilder.Entity<address>()
.Property(e => e.phone)
.IsUnicode(false);
modelBuilder.Entity<address>()
.HasMany(e => e.customers)
.WithRequired(e => e.address)
.WillCascadeOnDelete(false);
modelBuilder.Entity<address>()
.HasMany(e => e.staffs)
.WithRequired(e => e.address)
.WillCascadeOnDelete(false);
modelBuilder.Entity<address>()
.HasMany(e => e.stores)
.WithRequired(e => e.address)
.WillCascadeOnDelete(false);
modelBuilder.Entity<category>()
.Property(e => e.name)
.IsUnicode(false);
modelBuilder.Entity<category>()
.HasMany(e => e.film_category)
.WithRequired(e => e.category)
.WillCascadeOnDelete(false);
modelBuilder.Entity<city>()
.Property(e => e.city1)
.IsUnicode(false);
modelBuilder.Entity<city>()
.HasMany(e => e.addresses)
.WithRequired(e => e.city)
.WillCascadeOnDelete(false);
modelBuilder.Entity<country>()
.Property(e => e.country1)
.IsUnicode(false);
modelBuilder.Entity<country>()
.HasMany(e => e.cities)
.WithRequired(e => e.country)
.WillCascadeOnDelete(false);
modelBuilder.Entity<customer>()
.Property(e => e.first_name)
.IsUnicode(false);
modelBuilder.Entity<customer>()
.Property(e => e.last_name)
.IsUnicode(false);
modelBuilder.Entity<customer>()
.Property(e => e.email)
.IsUnicode(false);
modelBuilder.Entity<customer>()
.HasMany(e => e.payments)
.WithRequired(e => e.customer)
.WillCascadeOnDelete(false);
modelBuilder.Entity<customer>()
.HasMany(e => e.rentals)
.WithRequired(e => e.customer)
.WillCascadeOnDelete(false);
modelBuilder.Entity<film>()
.Property(e => e.title)
.IsUnicode(false);
modelBuilder.Entity<film>()
.Property(e => e.description)
.IsUnicode(false);
modelBuilder.Entity<film>()
.Property(e => e.rating)
.IsUnicode(false);
modelBuilder.Entity<film>()
.Property(e => e.special_features)
.IsUnicode(false);
modelBuilder.Entity<film>()
.HasMany(e => e.film_actor)
.WithRequired(e => e.film)
.WillCascadeOnDelete(false);
modelBuilder.Entity<film>()
.HasMany(e => e.film_category)
.WithRequired(e => e.film)
.WillCascadeOnDelete(false);
modelBuilder.Entity<film>()
.HasMany(e => e.inventories)
.WithRequired(e => e.film)
.WillCascadeOnDelete(false);
modelBuilder.Entity<film_text>()
.Property(e => e.title)
.IsUnicode(false);
modelBuilder.Entity<film_text>()
.Property(e => e.description)
.IsUnicode(false);
modelBuilder.Entity<inventory>()
.HasMany(e => e.rentals)
.WithRequired(e => e.inventory)
.WillCascadeOnDelete(false);
modelBuilder.Entity<language>()
.Property(e => e.name)
.IsUnicode(false);
modelBuilder.Entity<language>()
.HasMany(e => e.films)
.WithRequired(e => e.language)
.HasForeignKey(e => e.language_id)
.WillCascadeOnDelete(false);
modelBuilder.Entity<language>()
.HasMany(e => e.films1)
.WithOptional(e => e.language1)
.HasForeignKey(e => e.original_language_id);
modelBuilder.Entity<staff>()
.Property(e => e.first_name)
.IsUnicode(false);
modelBuilder.Entity<staff>()
.Property(e => e.last_name)
.IsUnicode(false);
modelBuilder.Entity<staff>()
.Property(e => e.email)
.IsUnicode(false);
modelBuilder.Entity<staff>()
.Property(e => e.username)
.IsUnicode(false);
modelBuilder.Entity<staff>()
.Property(e => e.password)
.IsUnicode(false);
modelBuilder.Entity<staff>()
.HasMany(e => e.payments)
.WithRequired(e => e.staff)
.WillCascadeOnDelete(false);
modelBuilder.Entity<staff>()
.HasMany(e => e.rentals)
.WithRequired(e => e.staff)
.WillCascadeOnDelete(false);
modelBuilder.Entity<staff>()
.HasMany(e => e.stores)
.WithRequired(e => e.staff)
.HasForeignKey(e => e.manager_staff_id)
.WillCascadeOnDelete(false);
modelBuilder.Entity<store>()
.HasMany(e => e.customers)
.WithRequired(e => e.store)
.WillCascadeOnDelete(false);
modelBuilder.Entity<store>()
.HasMany(e => e.inventories)
.WithRequired(e => e.store)
.WillCascadeOnDelete(false);
modelBuilder.Entity<store>()
.HasMany(e => e.staffs)
.WithRequired(e => e.store)
.HasForeignKey(e => e.store_id)
.WillCascadeOnDelete(false);
}
}
我的模特
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("sakila.actor")]
public partial class actor
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public actor()
{
film_actor = new HashSet<film_actor>();
}
[Key]
[Column(TypeName = "usmallint")]
public int actor_id { get; set; }
[Required]
[StringLength(45)]
public string first_name { get; set; }
[Required]
[StringLength(45)]
public string last_name { get; set; }
[Column(TypeName = "timestamp")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public DateTime last_update { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<film_actor> film_actor { get; set; }
}
有人可以帮忙解决这个问题吗?
答案 0 :(得分:0)
问题是由于我安装的软件。它阻止了所有不允许的流量网络访问。
检查系统中是否有任何流量过滤软件