All models created, before making migrations
This commit is contained in:
44
BlogPlatform/BlogPlatform/BlogPlatformDbContext.cs
Normal file
44
BlogPlatform/BlogPlatform/BlogPlatformDbContext.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using BlogPlatform.Models;
|
||||||
|
|
||||||
|
namespace BlogPlatform;
|
||||||
|
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
|
||||||
|
public class BlogPlatformDbContext: DbContext
|
||||||
|
{
|
||||||
|
public DbSet<Comment> Comments { get; set; }
|
||||||
|
public DbSet<Post> Posts { get; set; }
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
string connectionString =
|
||||||
|
"Server=romaric-thibault.fr;" +
|
||||||
|
"Database=BlogPlatform_cristiano;" +
|
||||||
|
"User Id=cristiano;" +
|
||||||
|
"Password=Onto9-Cage-Afflicted;" +
|
||||||
|
"TrustServerCertificate=True";
|
||||||
|
|
||||||
|
optionsBuilder.UseSqlServer(connectionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<Comment>()
|
||||||
|
.Property(comment => comment.CreatedAt)
|
||||||
|
.HasDefaultValueSql("getdate()")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
modelBuilder.Entity<Post>()
|
||||||
|
.Property(post => post.CreatedAt)
|
||||||
|
.HasDefaultValueSql("getdate()")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
modelBuilder.Entity<User>()
|
||||||
|
.Property(user => user.CreatedAt)
|
||||||
|
.HasDefaultValueSql("getdate()")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
}
|
||||||
|
}
|
@@ -7,4 +7,10 @@ public class Comment
|
|||||||
[Key] public int Id { get; set; }
|
[Key] public int Id { get; set; }
|
||||||
[Required, Length(1,500)] public string? Content { get; set; }
|
[Required, Length(1,500)] public string? Content { get; set; }
|
||||||
public DateOnly CreatedAt { get; set; }
|
public DateOnly CreatedAt { get; set; }
|
||||||
|
|
||||||
|
[Required] public int PostId{ get; set; }
|
||||||
|
public Post? Post{ get; set; }
|
||||||
|
|
||||||
|
[Required] public int UserId { get; set; }
|
||||||
|
public User? User{ get; set; }
|
||||||
}
|
}
|
@@ -9,4 +9,9 @@ public class Post
|
|||||||
[Required] public string? Content { get; set; }
|
[Required] public string? Content { get; set; }
|
||||||
[Required] public int Likes { get; set; }
|
[Required] public int Likes { get; set; }
|
||||||
public DateOnly CreatedAt { get; set; }
|
public DateOnly CreatedAt { get; set; }
|
||||||
|
|
||||||
|
public List<Comment>? Comments { get; set; }
|
||||||
|
|
||||||
|
[Required] public int UserId { get; set; }
|
||||||
|
public User? User{ get; set; }
|
||||||
}
|
}
|
@@ -11,5 +11,6 @@ public class User
|
|||||||
[Required,Length(24,24)] public string? Salt { get; set; }
|
[Required,Length(24,24)] public string? Salt { get; set; }
|
||||||
public DateOnly CreatedAt { get; set; }
|
public DateOnly CreatedAt { get; set; }
|
||||||
|
|
||||||
|
public List<Comment>? Comments { get; set; }
|
||||||
|
public List<Post>? Posts { get; set; }
|
||||||
}
|
}
|
Reference in New Issue
Block a user