Ejemplo n.º 1
0
        protected override void OnModelCreating(Data.Entity.ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.UseSqlServerIdentityColumns();

            // TODO GitHubIssue#57: Complete EF7 to EDM model mapping
            // After EF7 adds support for DataAnnotation, some of following configuration could be deprecated.

            modelBuilder.Entity <Category>(entityBuilder =>
            {
                entityBuilder.ToTable("Categories");
                entityBuilder.Property(e => e.CategoryName).IsRequired().HasMaxLength(15);
                entityBuilder.Property(e => e.Description).HasSqlServerColumnType("ntext");
                entityBuilder.Property(e => e.Picture).HasSqlServerColumnType("image");
                entityBuilder.Property(e => e.CategoryName).HasMaxLength(15);
                entityBuilder.HasKey(e => e.CategoryID);
            });


            modelBuilder.Entity <Contact>(entityBuilder =>
            {
                entityBuilder.ToTable("Contacts");
                entityBuilder.Property(e => e.HomePage).HasSqlServerColumnType("ntext");
                entityBuilder.Property(e => e.Photo).HasSqlServerColumnType("image");
                //entityBuilder.Key(e => e.ContactID);
            });

            modelBuilder.Entity <Customer>(entityBuilder =>
            {
                entityBuilder.ToTable("Customers");
                entityBuilder.Property(e => e.CompanyName).IsRequired().HasMaxLength(40);
                entityBuilder.HasKey(e => e.CustomerID);
            });

            modelBuilder.Entity <Employee>(entityBuilder =>
            {
                entityBuilder.ToTable("Employees");
                entityBuilder.Property(e => e.LastName).IsRequired().HasMaxLength(20);
                entityBuilder.Property(e => e.FirstName).IsRequired().HasMaxLength(10);
                entityBuilder.HasMany(e => e.Employees1).WithOne(e => e.Employee1).Required(false).ForeignKey(e => e.ReportsTo);
            });

            modelBuilder.Entity <Order>(entityBuilder =>
            {
                entityBuilder.ToTable("Orders");
                entityBuilder.HasMany(e => e.Order_Details).WithOne(e => e.Order).Required().ForeignKey(e => e.OrderID);
            });

            modelBuilder.Entity <Order_Detail>(entityBuilder =>
            {
                entityBuilder.ToTable("Order Details");
                entityBuilder.Property(e => e.UnitPrice).HasSqlServerColumnType("money");
                entityBuilder.HasKey(e => new
                {
                    K1 = e.OrderID,
                    K2 = e.ProductID,
                });
            });

            modelBuilder.Entity <Product>(entityBuilder =>
            {
                entityBuilder.ToTable("Products");
                entityBuilder.Property(e => e.UnitPrice).HasSqlServerColumnType("money");
                entityBuilder.HasMany(e => e.Order_Details).WithOne(e => e.Product).Required();
            });

            modelBuilder.Entity <Region>(entityBuilder =>
            {
                entityBuilder.Property(e => e.RegionDescription).IsRequired();
                entityBuilder.HasKey(e => e.RegionID);
            });

            modelBuilder.Entity <Shipper>(entityBuilder =>
            {
                entityBuilder.ToTable("Shippers");
                entityBuilder.HasMany(e => e.Orders).WithOne(e => e.Shipper).ForeignKey(e => e.ShipVia).Required(false);
            });

            modelBuilder.Entity <Supplier>(entityBuilder =>
            {
            });

            modelBuilder.Entity <Territory>(entityBuilder =>
            {
                entityBuilder.ToTable("Territories");
            });

            // TODO GitHubIssue#57: Complete EF7 to EDM model mapping
            // ToTable() is not yet supported in EF7, remove following ignores after it's ready.
            modelBuilder.Ignore <CustomerDemographic>();

            modelBuilder.Entity <Customer>().Ignore(e => e.CustomerDemographics);

            modelBuilder.Entity <Employee>().Ignore(e => e.Territories);

            modelBuilder.Entity <Territory>().Ignore(e => e.Employees);
        }
Ejemplo n.º 2
0
        protected override void OnModelCreating(Data.Entity.ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.ForSqlServer().UseIdentity();

            // TODO GitHubIssue#57: Complete EF7 to EDM model mapping
            // After EF7 adds support for DataAnnotation, some of following configuration could be deprecated.
            modelBuilder.Entity <Alphabetical_list_of_product>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Alphabetical list of products");
                entityBuilder.Property(e => e.UnitPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Property(e => e.ProductName).MaxLength(40);
                entityBuilder.Property(e => e.QuantityPerUnit).MaxLength(40);
                entityBuilder.Property(e => e.CategoryName).MaxLength(15);
                entityBuilder.Key(e => new
                {
                    K1 = e.ProductID,
                    K2 = e.ProductName,
                    K3 = e.Discontinued,
                    K4 = e.CategoryName,
                });
            });

            modelBuilder.Entity <Category>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Categories");
                entityBuilder.Property(e => e.CategoryName).Required().MaxLength(15);
                entityBuilder.Property(e => e.Description).ForSqlServer().ColumnType("ntext");
                entityBuilder.Property(e => e.Picture).ForSqlServer().ColumnType("image");
                entityBuilder.Property(e => e.CategoryName).MaxLength(15);
                entityBuilder.Key(e => e.CategoryID);
            });

            modelBuilder.Entity <Category_Sales_for_1997>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Category Sales for 1997");
                entityBuilder.Property(e => e.CategoryName).MaxLength(15);
                entityBuilder.Property(e => e.CategorySales).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => e.CategoryName);
            });

            modelBuilder.Entity <Contact>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Contacts");
                entityBuilder.Property(e => e.HomePage).ForSqlServer().ColumnType("ntext");
                entityBuilder.Property(e => e.Photo).ForSqlServer().ColumnType("image");
                //entityBuilder.Key(e => e.ContactID);
            });

            modelBuilder.Entity <Current_Product_List>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Current Product List");
                entityBuilder.Key(e => new
                {
                    K1 = e.ProductID,
                    K2 = e.ProductName,
                });
            });

            modelBuilder.Entity <Customer>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Customers");
                entityBuilder.Property(e => e.CompanyName).Required().MaxLength(40);
                entityBuilder.Key(e => e.CustomerID);
            });

            modelBuilder.Entity <Customer_and_Suppliers_by_City>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Customer and Suppliers by City");
                //entityBuilder.Property(e => e.CompanyName).Required().MaxLength(40);
                entityBuilder.Key(e => new
                {
                    K1 = e.CompanyName,
                    K2 = e.Relationship,
                });
            });

            modelBuilder.Entity <Employee>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Employees");
                entityBuilder.Property(e => e.LastName).Required().MaxLength(20);
                entityBuilder.Property(e => e.FirstName).Required().MaxLength(10);
                entityBuilder.Collection(e => e.Employees1).InverseReference(e => e.Employee1).Required(false).ForeignKey(e => e.ReportsTo);
            });

            modelBuilder.Entity <Invoice>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Invoices");
                entityBuilder.Property(e => e.UnitPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Property(e => e.ExtendedPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Property(e => e.Freight).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => new
                {
                    K1 = e.CustomerName,
                    K2 = e.Salesperson,
                    K3 = e.OrderID,
                    K4 = e.ShipperName,
                    K5 = e.ProductID,
                    K6 = e.ProductName,
                    K7 = e.UnitPrice,
                    K8 = e.Quantity,
                    K9 = e.Discount,
                });
            });

            modelBuilder.Entity <Order>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Orders");
                entityBuilder.Collection(e => e.Order_Details).InverseReference(e => e.Order).Required().ForeignKey(e => e.OrderID);
            });

            modelBuilder.Entity <Order_Detail>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Order Details");
                entityBuilder.Property(e => e.UnitPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => new
                {
                    K1 = e.OrderID,
                    K2 = e.ProductID,
                });
            });

            modelBuilder.Entity <Order_Details_Extended>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Order Details Extended");
                entityBuilder.Property(e => e.UnitPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Property(e => e.ExtendedPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => new
                {
                    K0 = e.OrderID,
                    K1 = e.ProductID,
                    K2 = e.ProductName,
                    K3 = e.UnitPrice,
                    K4 = e.Quantity,
                    K5 = e.Discount,
                });
            });

            modelBuilder.Entity <Order_Subtotal>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Order Subtotals");
                entityBuilder.Property(e => e.Subtotal).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => e.OrderID);
            });

            modelBuilder.Entity <Orders_Qry>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Order Qry");
                entityBuilder.Property(e => e.Freight).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => new
                {
                    K0 = e.OrderID,
                    K1 = e.CompanyName,
                });
            });

            modelBuilder.Entity <Product>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Products");
                entityBuilder.Property(e => e.UnitPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Collection(e => e.Order_Details).InverseReference(e => e.Product).Required();
            });

            modelBuilder.Entity <Product_Sales_for_1997>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Product Sales for 1997");
                entityBuilder.Property(e => e.ProductSales).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => new
                {
                    K0 = e.CategoryName,
                    K1 = e.ProductName,
                });
            });

            modelBuilder.Entity <Products_Above_Average_Price>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Products Above Average Price");
                entityBuilder.Property(e => e.UnitPrice).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => e.ProductName);
            });

            modelBuilder.Entity <Products_by_Category>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Products by Category");
                entityBuilder.Key(e => new
                {
                    K0 = e.CategoryName,
                    K1 = e.ProductName,
                    K2 = e.Discontinued,
                });
            });

            modelBuilder.Entity <Region>(entityBuilder =>
            {
                entityBuilder.Property(e => e.RegionDescription).Required();
                entityBuilder.Key(e => e.RegionID);
            });

            modelBuilder.Entity <Sales_by_Category>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Sales by Category");
                entityBuilder.Property(e => e.ProductSales).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => new
                {
                    K0 = e.CategoryID,
                    K1 = e.CategoryName,
                    K2 = e.ProductName,
                });
            });

            modelBuilder.Entity <Sales_Totals_by_Amount>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Sales Totals by Amount");
                entityBuilder.Property(e => e.SaleAmount).ForSqlServer().ColumnType("money");
                entityBuilder.Key(e => new
                {
                    K0 = e.OrderID,
                    K1 = e.CompanyName,
                });
            });

            modelBuilder.Entity <Shipper>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Shippers");
                entityBuilder.Collection(e => e.Orders).InverseReference(e => e.Shipper).ForeignKey(e => e.ShipVia).Required(false);
            });

            modelBuilder.Entity <Summary_of_Sales_by_Quarter>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Summary of Sales by Quarter");
                entityBuilder.Property(e => e.Subtotal).ForSqlServer().ColumnType("money");
                entityBuilder.Property(e => e.OrderID).StoreGeneratedPattern(StoreGeneratedPattern.None);
                entityBuilder.Key(e => e.OrderID);
            });

            modelBuilder.Entity <Summary_of_Sales_by_Year>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Summary of Sales by Year");
                entityBuilder.Property(e => e.Subtotal).ForSqlServer().ColumnType("money");
                entityBuilder.Property(e => e.OrderID).StoreGeneratedPattern(StoreGeneratedPattern.None);
                entityBuilder.Key(e => e.OrderID);
            });

            modelBuilder.Entity <Supplier>(entityBuilder =>
            {
            });

            modelBuilder.Entity <sysdiagram>(entityBuilder =>
            {
                entityBuilder.Property(e => e.name).Required();
                entityBuilder.Key(e => e.diagram_id);
            });

            modelBuilder.Entity <Territory>(entityBuilder =>
            {
                entityBuilder.ForSqlServer().Table("Territories");
            });

            // TODO GitHubIssue#57: Complete EF7 to EDM model mapping
            // ToTable() is not yet supported in EF7, remove following ignores after it's ready.
            modelBuilder.Ignore <CustomerDemographic>();

            modelBuilder.Entity <Customer>().Ignore(e => e.CustomerDemographics);

            modelBuilder.Entity <Employee>().Ignore(e => e.Territories);

            modelBuilder.Entity <Territory>().Ignore(e => e.Employees);
        }