Reputation: 2636
Using MS visual studio 2012, Asp.net C# MVC 4, Entity Framework, NopCommerce(cms).
Hi guys I have Database Design Query, its actual confused me, normally I have no problems with DBs.
However since transitioning over to the Code First approach I asked my self this question...
I am Creating a new plugin for my NopCommerce CMS website, This plugin shall be a ImageGallery Plugin.
I would like the Data layer to store an
ID,
Name,
LargeImg
SmallImg,
Urlimg
But I also want to realize the functionality of this Plugin, The user should be able to upload any image and then Associate this image to a section of there choosing, What i mean by this is Img to a blog post, or Img to news post, Img to a product post OR all of the 3.
Now these three examples are the only ones i can think of, but as you have guessed this may change depending on additional content types.
Now Instantly I thought, Easy we simply create a field called.....Type? or ContentType? this field will then store the "type" of image association, whether it is a Blog, news or product item.
At which point i thought of "but what if an image has multiple associations?
To which brings me to the question, in this situation, Should i:
For some reason I'm stuck, I don't normally draw a blank on DB design and implementation.
The code below is my Domain Class in my plugin, i went for number 2 but im not sure to continue down this road.
using Nop.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hroc.Plugin.Misc.ImageGallery.Domain
{
public class ImageItem : BaseEntity
{
public virtual int ImageID { get; set; }
public virtual string Name { get; set; }
public virtual byte[] Largeimg { get; set; }
public virtual byte[] Smallimg { get; set; }
public virtual string URLimg { get; set; }
public virtual string Typeimg { get; set; }
public virtual int LinkID { get; set; }
}
}
hopefully you guys can point out the correct way to implement this, thanks!
Upvotes: 0
Views: 328
Reputation: 152566
With everything there is a trade-off
Benefits of normalization in your case:
Drawbacks:
If I were designing this feature I would go with Option 3 - normalizing the content types has other advantages such as being able to use that table for drop-down lists.
Upvotes: 1