在我的專案中,一個顯示幕應該有很多媒體(影像、視頻)。我正在使用 Entity Framework Core 來構建我的資料庫,并使用我的 API 控制器來構建 CRUD。
我這樣設計了我的模型類:
[Table("Displays")]
public class Display : ConcurrencyCheck
{
[Key]
public int Id { get; set; }
[Required(ErrorMessage = "{0} skal udfyldes!")]
[Display(Name = "Display navn")]
public string Name { get; set; }
[Display(Name = "Display t?ndt")]
public bool IsOn { get; set; }
[Display(Name = "Display beskrivelse")]
public string Description { get; set; }
public IEnumerable<Video> Videos { get; set; }
public IEnumerable<Image> Images { get; set; }
}
public abstract class Media : ConcurrencyCheck
{
[Key]
public int Id { get; set; }
[Required(ErrorMessage = "{0} skal udfyldes!")]
[Display(Name = "Medie navn")]
public string Name { get; set; }
[Display(Name = "Medie beskrivelse")]
public string Description { get; set; }
[Display(Name = "Medie filtype")]
public string FileType { get; set; }
[Required(ErrorMessage = "{0} skal udfyldes!")]
[Display(Name = "Medie filsti")]
public string FilePath { get; set; }
public int? DisplayId { get; set; }
[ForeignKey("DisplayId")]
public Display Display { get; set; }
}
[Table("Videos")]
public class Video : Media
{
[Display(Name = "Frames")]
public int Frames { get; set; }
[Display(Name = "Filsti p? undetekster")]
public string SubtitlesPath { get; set; }
[Display(Name = "Filsti p? thumbnail")]
public string ThumbnailPath { get; set; }
}
[Table("Images")]
public class Image : Media
{
}
public abstract class ConcurrencyCheck
{
[Timestamp]
public byte[] RowVersion { get; set; }
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy HH:mm}", ApplyFormatInEditMode = true)]
public DateTime CreatedDate { get; set; }
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy HH:mm}", ApplyFormatInEditMode = true)]
public DateTime? UpdatedDate { get; set; }
}
我的 API 控制器是用“使用物體框架的帶有操作的 API 控制器”搭建的。
目前在 api-controller 'DisplaysController' 中,我看不到.Include(x => x.Media),雖然我在某處讀到它使用過?一個顯示幕應該有許多媒體(影像、視頻)。
我應該以某種方式將它包含在某個地方,還是它會由我擁有的模型自動執行?
uj5u.com熱心網友回復:
scaffolded with API Controller with actions, using Entity Framework只是提供了最基本的五種資料庫操作方法—— select、、、select by id和。其目的是幫助用戶更快、更輕松地構建基礎。您可以在默認代碼模板上添加自己的代碼。updateadddeletecrud
默認代碼模板

添加自己的代碼

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/444903.html
標籤:实体框架 asp.net 核心 asp.net-web-api 实体框架核心 asp.net-core-webapi
上一篇:影像的延遲渲染-SkiaASP
