在我IdentityModels類我有一個屬性叫做報告像下面連接兩個表並返回DbSet對象
public DbSet<Report> Reports { get; set; }
我的數據庫中有與此屬性從拉數據的相同名稱的表。
我也有一個叫做報告模型(除了一些其他屬性),具有這些
public class Report
{
//...
[Required]
public string State { get; set; }
[Column("reporter_id")]
public string ReporterId { get; set; }
[Required]
[Column("report_text")]
public string ReportText { get; set; }
//...
}
我也有一種觀點認爲是報告一個強烈的意見作爲其模型。
當我遇到了一個問題是,我的模型有reporterId這是一個外鍵不同的表叫AspNetUsers
有用戶的詳細信息。
我想不會顯示用戶名ID和因爲報告表不僅具有用戶id有沒有辦法對我來說,顯示用戶名。
將AspNetUsers
表中的user_name
字段作爲我的模型的一部分的什麼方法?顯然必須在reports
表和aspNetUsers
表之間存在join
聲明,但我不確定如何最好地執行此操作。
你可以把一個'AspNetUsers'模式也? – Sampath
你沒有把'userId'放在'Report'模型上? – Sampath
我在我的'Report'模型用戶ID(屬性稱爲'ReporterId'),但我需要使用「用戶名」,從「AspNetUsers」表,因爲我想要的用戶名不是用戶ID –