开发者

Database fields classing with defined classes (class design troubles)

My database is relational so I have a CategoryID property in my products table and categoryName and categoryID in my Category table and class.

my problem is that sometimes when i query my tables I bring back different results. For example in my category table I bring back the categoryName from the category Id in my products table.

So, now I have a categoryName in my product class with no property called categoryName.

I have two solutions, just add random properties to my product class holding the names of category name and merchant name, deppending on the values I bring back or create another class with the values I bring back from the query. Both which i think is a bad way of doing this.

for example

product class product id merchant id product name

category class product id product name

merchant 开发者_开发问答class merchant id merchant name

new class category id category name product name

i hope i made this as easily as possible to understand.

My Classes are

public class Product
    {
        public string productId  { get; set;}
        public string productName  { get; set;}
        public string productDescription  { get; set;}
        public string productImage  { get; set;}
        public string trackPrice  { get; set;}
        public string merchantId  { get; set;}
        public string categoryId  { get; set;}
        public int brandId  { get; set;}
    }


public class Brand
        {
            public string brandId { get; set;}
            public string brandName { get; set;}
        }

I query my code from the database bringing back just productId, productName, BrandId and BrandName.

Then loop through my records displaying the records in a row. I now have values which cross between both classes.

Should I create a new class such as...

public class DisplayProducts
    {
        public string productId  { get; set;}
        public string productName  { get; set;}
        public string brandId { get; set;}
        public string brandName { get; set;}
    }

or add properties to existing classes?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜