コード例 #1
0
ファイル: Seeder.cs プロジェクト: dibble-james/Ketchup
        public static void AddProductCategory(KetchupContext context)
        {
            var price = context.ProductAttributeTypes.First(pat => pat.Name == "Price");
            var name = context.ProductAttributeTypes.First(pat => pat.Name == "Name");

            var category = new ProductCategory
            {
                Name = "Default Product Category"
            };

            context.ProductCategorys.AddOrUpdate(pc => pc.Name, category);

            var specifications = new []
            {
                new ProductCategorySpecificationAttribute
                {
                    Attribute = price,
                    ProductCategory = category,
                    ProductAttributeTypeId = price.Id,
                    ProductCategoryId = category.Id
                },
                new ProductCategorySpecificationAttribute
                {
                    Attribute = name,
                    ProductCategory = category,
                    ProductAttributeTypeId = price.Id,
                    ProductCategoryId = category.Id
                },
            };

            context.ProductCategorySpecificationAttributes.AddOrUpdate(
                pcsa => new { pcsa.ProductAttributeTypeId, pcsa.ProductCategoryId },
                specifications);
        }
コード例 #2
0
ファイル: Seeder.cs プロジェクト: dibble-james/Ketchup
        public static void AddProductAttributeTypes(KetchupContext context)
        {
            context.ProductAttributeTypes.AddOrUpdate(new ProductAttributeType
            {
                Name = "Price",
                DisplayName = "Product Price",
                ValidationRegularExpression = @"^\d+[.]{1}(\d){2}$"
            });

            context.ProductAttributeTypes.AddOrUpdate(new ProductAttributeType
            {
                Name = "Name",
                DisplayName = "Product Name",
                ValidationRegularExpression = @"^$"
            });

            context.SaveChanges();
        }