-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1719024
commit c536c05
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
DAL/MODELS.FileSharing/Entities/Configuration/LinkConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace MODELS.FileSharing.Entities.Configuration; | ||
|
||
public class LinkConfiguration : IEntityTypeConfiguration<Link> | ||
{ | ||
public void Configure(EntityTypeBuilder<Link> builder) | ||
{ | ||
// query filters | ||
|
||
// properties | ||
builder.Property(l => l.CreatedAt).HasDefaultValueSql("GetDate()"); | ||
builder.Property(l => l.Display) | ||
.HasComputedColumnSql("[Name]", stored: true); | ||
|
||
// relationships | ||
builder.HasOne(l => l.FileItemNavigation) | ||
.WithMany(f => f.Links) | ||
.HasForeignKey(l => l.FileItemId) | ||
.OnDelete(DeleteBehavior.Cascade) | ||
.HasConstraintName("FK_Links_FileItem"); | ||
|
||
builder.HasOne(l => l.UserNavigation) | ||
.WithMany(u => u.Links) | ||
.HasForeignKey(l => l.UserId) | ||
.OnDelete(DeleteBehavior.Cascade) | ||
.HasConstraintName("FK_Links_User"); | ||
|
||
builder.HasIndex(l => l.url, "IX_Links_Url").IsUnique(); | ||
|
||
// temporal | ||
builder.ToTable(b => b.IsTemporal(tb => | ||
{ | ||
tb.HasPeriodEnd("ValidTo"); | ||
tb.HasPeriodStart("ValidFrom"); | ||
tb.UseHistoryTable("FileItemsAudit"); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace MODELS.FileSharing.Entities; | ||
|
||
[Table("Links", Schema = "dbo")] | ||
[EntityTypeConfiguration(typeof(LinkConfiguration))] | ||
public partial class Link : BaseEntity | ||
{ | ||
#region fields | ||
[Required] | ||
public string url { get; set; } | ||
|
||
[Required] | ||
[DisplayName("File Item")] | ||
public int FileItemId { get; set; } | ||
|
||
[ForeignKey(nameof(FileItemId))] | ||
[InverseProperty(nameof(FileItem.Links))] | ||
public virtual FileItem FileItemNavigation { get; set; } | ||
|
||
[Required] | ||
public DateTime CreatedAt { get; set; } | ||
|
||
[Required] | ||
public DateTime ValidTo { get; set; } | ||
|
||
[Required] | ||
public DateTime LastChanged { get; set; } | ||
|
||
[Required] | ||
[DisplayName("Owner")] | ||
public int UserId { get; set; } | ||
|
||
[ForeignKey(nameof(UserId))] | ||
[InverseProperty(nameof(User.Links))] | ||
public virtual User UserNavigation { get; set; } | ||
|
||
public bool IsActive { get; set; } | ||
|
||
[StringLength(200)] | ||
public string? Name { get; set; } | ||
|
||
public string? Description { get; set; } | ||
|
||
[DatabaseGenerated(DatabaseGeneratedOption.Computed)] | ||
public string? Display { get; set; } | ||
#endregion | ||
|
||
#region ctors | ||
public Link() | ||
{ | ||
// TODO | ||
} | ||
#endregion | ||
|
||
#region methods | ||
public override string ToString() | ||
{ | ||
return $"{Name} is a Link from {UserNavigation.UserName} with ID {Id}"; | ||
} | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters