Reputation: 6839
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.
Upvotes: 1
Views: 2541
Reputation: 15158
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.)
Upvotes: 1