我一直在研究Sanderson的“Pro ASP.NET MVC 2框架”一书。到目前为止一直是物理性的..。就在我认为我知道的够多的时候,我找到了一本书,它向我展示了我所知道的是多么的少。
我不太了解的事情之一是如何使用LINQtoSQL。在史蒂文的书中,第4-6章创造了一个非常好的小购物车。我读完了教程,一切都正常了。现在,我想修改购物车,使其使用一个类别表,而不是将类别名称作为varchar存储在Product中。
下面是Product对象,我的更改是将CategoryID作为与类别表的外键关系。
[Table(Name="Products")]
public class Product
{
[HiddenInput(DisplayValue=false)]
[Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
public int ProductID { get; set; }
[Required(ErrorMessage="Please enter a product name")]
[Column] public string Name { get; set; }
[Required(ErrorMessage="Please enter a description")]
[DataType(DataType.MultilineText)]
[Column] public string Description { get; set; }
[Required]
[Range(0.01, double.MaxValue, ErrorMessage="Please enter a positive price")]
[Column] public decimal Price { get; set; }
[Required(ErrorMessage="Please enter a category")]
[Column] public int CategoryID { get; set; }
internal EntityRef<Category> _category;
[System.Data.Linq.Mapping.Association(ThisKey = "CategoryID", Storage = "_category")]
public Category Category {
get { return _category.Entity; }
internal set { _category.Entity = value; CategoryID = value.CategoryID; }
}
[Column] public byte[] ImageData { get; set; }
[ScaffoldColumn(false)]
[Column] public string ImageMimeType { get; set; }这是我的分类课
[Table(Name="Categories")]
class Category
{
[Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
internal int CategoryID { get; set; }
[Column]
public int ParentCategoryID { get; set; }
[Column]
[Required]
public string Name { get; set; }
}当我试图构建这段代码时,我发现了一个我不明白的错误:
不一致的可访问性:属性类型‘'SportsStore.Domain.Entities.Product.Category’‘比属性
更难访问
这意味着什么/我将如何解决这个问题?
发布于 2010-08-12 21:05:33
你的类“类别”比“产品”更不明显。“产品”具有公共财产的“类别”,这是公开的。这就是“不一致的可访问性”。
您必须声明您的类“类别”与“产品”一样公开。
https://stackoverflow.com/questions/3471987
复制相似问题