0

I am building web application that allow users to upload their images.
Images can be of different types (recipes, articles, tips ... and profile images).
I have a little confusion about Profile Images.
I am using entity framework code first and I can't model 1-0 or 1.
But I have made a relation like on the image bellow and I need confirmation about this design is it good or bad? Does it have some flaws?

User can upload any type of image and I know who uploaded image based on CreatedBy Field.
And user can upload profile image and in that case in application I will just update ImageId field in Users table.

enter image description here

1110
  • 7,829
  • 55
  • 176
  • 334
  • 1 : 0-1 does work in EF. http://msdn.microsoft.com/en-us/data/jj591620#RequiredToOptional in principal what you are trying is Ok in my view – phil soady Jul 05 '14 at 15:43
  • What do you mean, "1-0 or 1"? Do you mean, 1-0:1? What do you mean you "can't" you model it? – philipxy Jul 05 '14 at 19:34
  • It seems that I confused my self and make much noise about simple thing. I aleady have 1-n and was trying to make 1-0:1 to same table. I just want to know is this design good for what I described in question? – 1110 Jul 05 '14 at 19:42

1 Answers1

1

You have two entity types, users and images; hence tables AspUsers & Image. You have relationships (in the everyday/ER sense): UserCreatedImage(UserId,ImageId) and UserProfileImage(UserId,ImageId).

The first is many:many in entities so gets its own table.

The second is 0-or-1:1 in images:users aka 1:0-or-1 in users:images. That is typically expressed by an ImageId column in AspUsers that is a nullable foreign key to ImageId in Image.

Assuming you add that, your design is reasonable.

(Because of the FK cycle between these tables--which is the proper model--you must code in Entity Framework in a certain way.)

Community
  • 1
  • 1
philipxy
  • 14,867
  • 6
  • 39
  • 83