简体   繁体   English

会员由于其保护级别而无法访问

[英]Member is inaccessible due to its protection level

ProductContext Category product I keep getting error code for both context.Categories.Add(c) and context.Prodcuts.Add(p) that it's inaccessible due to it's protection level. ProductContext Category产品我不断收到context.Categories.Add(c)context.Prodcuts.Add(p)错误代码,由于它的保护级别,它无法访问。 Everything seems correct.一切似乎都是正确的。 Please help me.请帮我。

namespace WingtipToys.Models
{
    public class ProductDatabaseInitializer: DropCreateDatabaseIfModelChanges <ProductContext>
    {
        protected override void Seed(ProductContext context)
        {
            GetCategories().ForEach(c => context.Categories.Add(c));
            GetProducts().ForEach(p => context.Products.Add(p));
        }
        private static List<Category> GetCategories()
        {
            var categories = new List<Category>
            {
                new Category
                {
                    CategoryID = 1,
                    CategoryName = "Cars"
                },
                new Category
                {
                    CategoryID = 2,
                    CategoryName = "PLANES"
                },
            };
            return categories;
        }
        private static List<Product> GetProducts()
        {
            var products = new List<Product>
            {
                new Product
                {
                    ProductID = 1,
                    ProductName = "Convertible Car",
                    Description = "This convertible Car is fast!",
                    ImagePath = "carconvert.png",
                    UnitPrice = 22.50,
                    CategoryID = 1
                },
            };
            return products;
        }
    }
}

You need to put public in front of your Dbset and DbSet if you want to use it like that.如果你想像那样使用它,你需要把 public 放在你的 Dbset 和 DbSet 的前面。 Take a look on Access Modifiers Try this:看看访问修饰符试试这个:

public DbSet<Category> Categories;
public DbSet<Product> Products;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM