1 Replies - 705 Views - Last Post: 17 September 2016 - 06:28 AM

#1 ibnmvungi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 20-April 12

sequence contains no matching element scaffolding code first from data

Posted 14 September 2016 - 08:20 AM

I am using Visual studio 2015 to create an ASP.NET MVC web Application using Mysql Database and EF6

The model is created using Code First From Database

Model

    [Table("mydb.customers")]
    public partial class customer
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public customer()
        {
            orders = new HashSet<order>();
            payments = new HashSet<payment>();
        }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int customerNumber { get; set; }

        [Required]
        [StringLength(50)]
        public string customerName { get; set; }

        [Required]
        [StringLength(50)]
        public string contactLastName { get; set; }

        [Required]
        [StringLength(50)]
        public string contactFirstName { get; set; }

        [Required]
        [StringLength(50)]
        public string phone { get; set; }

        [Required]
        [StringLength(50)]
        public string addressLine1 { get; set; }

        [StringLength(50)]
        public string addressLine2 { get; set; }

        [Required]
        [StringLength(50)]
        public string city { get; set; }

        [StringLength(50)]
        public string state { get; set; }

        [StringLength(15)]
        public string postalCode { get; set; }

        [Required]
        [StringLength(50)]
        public string country { get; set; }

        public int? salesRepEmployeeNumber { get; set; }

        public decimal? creditLimit { get; set; }

        public virtual employee employee { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<order> orders { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<payment> payments { get; set; }
    }




MY DbContext Class

  public partial class Model1 : DbContext
    {
        public Model1()
            : base("name=Model11")
        {
        }

        public virtual DbSet<customer> customers { get; set; }
        public virtual DbSet<employee> employees { get; set; }
        public virtual DbSet<office> offices { get; set; }
        public virtual DbSet<orderdetail> orderdetails { get; set; }
        public virtual DbSet<order> orders { get; set; }
        public virtual DbSet<payment> payments { get; set; }
        public virtual DbSet<productline> productlines { get; set; }
        public virtual DbSet<product> products { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<customer>()
                .Property(e => e.customerName)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.contactLastName)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.contactFirstName)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.phone)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.addressLine1)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.addressLine2)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.city)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.state)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.postalCode)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .Property(e => e.country)
                .IsUnicode(false);

            modelBuilder.Entity<customer>()
                .HasMany(e => e.orders)
                .WithRequired(e => e.customer)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<customer>()
                .HasMany(e => e.payments)
                .WithRequired(e => e.customer)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.lastName)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.firstName)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.extension)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.email)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.officeCode)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.jobTitle)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.username)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .Property(e => e.password)
                .IsUnicode(false);

            modelBuilder.Entity<employee>()
                .HasMany(e => e.customers)
                .WithOptional(e => e.employee)
                .HasForeignKey(e => e.salesRepEmployeeNumber);

            modelBuilder.Entity<employee>()
                .HasMany(e => e.employees1)
                .WithOptional(e => e.employee1)
                .HasForeignKey(e => e.reportsTo);

            modelBuilder.Entity<office>()
                .Property(e => e.officeCode)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.city)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.phone)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.addressLine1)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.addressLine2)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.state)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.country)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.postalCode)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .Property(e => e.territory)
                .IsUnicode(false);

            modelBuilder.Entity<office>()
                .HasMany(e => e.employees)
                .WithRequired(e => e.office)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<orderdetail>()
                .Property(e => e.productCode)
                .IsUnicode(false);

            modelBuilder.Entity<order>()
                .Property(e => e.status)
                .IsUnicode(false);

            modelBuilder.Entity<order>()
                .Property(e => e.comments)
                .IsUnicode(false);

            modelBuilder.Entity<order>()
                .HasMany(e => e.orderdetails)
                .WithRequired(e => e.order)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<payment>()
                .Property(e => e.checkNumber)
                .IsUnicode(false);

            modelBuilder.Entity<productline>()
                .Property(e => e.productLine1)
                .IsUnicode(false);

            modelBuilder.Entity<productline>()
                .Property(e => e.textDescription)
                .IsUnicode(false);

            modelBuilder.Entity<productline>()
                .Property(e => e.htmlDescription)
                .IsUnicode(false);

            modelBuilder.Entity<productline>()
                .HasMany(e => e.products)
                .WithRequired(e => e.productline1)
                .HasForeignKey(e => e.productLine)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<product>()
                .Property(e => e.productCode)
                .IsUnicode(false);

            modelBuilder.Entity<product>()
                .Property(e => e.productName)
                .IsUnicode(false);

            modelBuilder.Entity<product>()
                .Property(e => e.productLine)
                .IsUnicode(false);

            modelBuilder.Entity<product>()
                .Property(e => e.productScale)
                .IsUnicode(false);

            modelBuilder.Entity<product>()
                .Property(e => e.productVendor)
                .IsUnicode(false);

            modelBuilder.Entity<product>()
                .Property(e => e.productDescription)
                .IsUnicode(false);

            modelBuilder.Entity<product>()
                .HasMany(e => e.orderdetails)
                .WithRequired(e => e.product)
                .WillCascadeOnDelete(false);
        }
    }



When Scaffolding using this model I get

Quote

There was an error running the selected code generator.
Unable to retrieve metadata for 'Project.Models.Customer'
Sequence contains no matching element


Any One With Idea How To solve this?

This post has been edited by ibnmvungi: 14 September 2016 - 08:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: sequence contains no matching element scaffolding code first from data

#2 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: sequence contains no matching element scaffolding code first from data

Posted 17 September 2016 - 06:28 AM

First thing I'd check is the error is referencing Customers but your model is named customers. Since C# is case sensitive this could be why it can't find the model.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1