views:

24

answers:

1

I've been working through the book Pro ASP.NET MVC 2 Framework by Steven Sanderson. So far it's been phenominal... just when i think I know a decent amount I find a book that shows me just how little I know.

One of the things I know little about is how to use LINQtoSQL. In Steven's book, chapters 4-6 create a very nice little shopping cart. I went through the tutorial and got everything working. Now I want to modify the cart to use a Category table instead of storing the category name as a varchar in the Product table.

Here's the Product table object with my changes to have CategoryID as a foreign key relationship to the Categories Table.

    [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; }

And here is my Category class

    [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; }
    }

When I tried to build this code, i got an error that I don't understand:

Inconsistent accessibility: property type 'SportsStore.Domain.Entities.Category' is less accessible than property 'SportsStore.Domain.Entities.Product.Category'

What does that mean / How would I fix this?

+1  A: 

Your class "Categroy" is less visibly then "Product". "Product" has a public Property "Category" which is public. This is the "Inconsistent accessibility".

You have to declare your class "Category" public like "Product"

Arthur
doh! Sometimes I wish I could take a question back. Thanks for the help.
quakkels