Making some properties being unique

This commit is contained in:
Cristiano
2025-10-17 08:43:33 +02:00
parent 616d2cf34d
commit 31a25ccf7a
5 changed files with 15 additions and 3 deletions

View File

@@ -40,5 +40,13 @@ public class BlogPlatformDbContext: DbContext
.Property(user => user.CreatedAt)
.HasDefaultValueSql("getdate()")
.ValueGeneratedOnAdd();
modelBuilder.Entity<Comment>()
.HasOne(c => c.User)
.WithMany(u => u.Comments)
.HasForeignKey(c => c.UserId)
.OnDelete(DeleteBehavior.NoAction);
}
}

View File

@@ -1,7 +1,11 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace BlogPlatform.Models;
// Making Email and Username being unique
[Index(nameof(Username), IsUnique = true)]
[Index(nameof(Email), IsUnique = true)]
public class User
{
[Key] public int Id { get; set; }

View File

@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("BlogPlatform")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+36c57c9d11394e2fbfc9056addd367ad64ad5ada")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+616d2cf34d4893e8eade7003c30cdca45f525111")]
[assembly: System.Reflection.AssemblyProductAttribute("BlogPlatform")]
[assembly: System.Reflection.AssemblyTitleAttribute("BlogPlatform")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
4893baab51a13176227e1d76a74ce5e02426ad1458555aacb49492b00b53a7c8
c3551b5ae7f295e4919a88c72840a4110a0c223f1672487e5268a6862aa8c707

View File

@@ -1 +1 @@
17606818161317519
17606831130087276