第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

API 模型中的空引用

API 模型中的空引用

C#
翻翻過去那場(chǎng)雪 2023-06-25 14:32:07
我正在嘗試通過使用代碼優(yōu)先方法生成數(shù)據(jù)庫(kù)來構(gòu)建標(biāo)準(zhǔn) REST API 來學(xué)習(xí) Entity Framework Core。我在從當(dāng)前端點(diǎn)返回的 JSON 中獲取了空值GET,可以幫助找出出錯(cuò)的地方。這些控制器當(dāng)前是 Entity Framework Core 生成的默認(rèn)支架控制器。GET問題是我安裝時(shí)返回的 JSON是:{    "installId": 1,    "aadUser": "Mr. Doe",    "progress": 0,    "practice": null  //Shouldn't this reference a specific Practice?}這是一對(duì)一的關(guān)系。型號(hào)類別:public class Install{    public long InstallId { get; set; }    public string AADUser { get; set; }    public int Progress { get; set; }    public Practice Practice { get; set; }}public class Practice{    public long PracticeId { get; set; }    public string Name { get; set; }    public string Specialty { get; set; }    public long InstallId { get; set; }    public Install Install { get; set; }    public ICollection<User> Users { get; set; }    public ICollection<User_Access> Users_Access { get; set; }    public ICollection<Billing> Billing { get; set; }    public ICollection<Location> Locations { get; set; }    public ICollection<Resource> Resources { get; set; }}上下文片段:protected override void OnModelCreating(ModelBuilder modelBuilder){        //Install        modelBuilder.Entity<Install>(entity =>        {            entity.HasKey(e => e.InstallId);            entity.HasOne(d => d.Practice)                .WithOne(p => p.Install)                .OnDelete(DeleteBehavior.Cascade);            //Seed Database            entity.HasData(new Install()                {                    InstallId = 1,                    AADUser = "Mr. Doe",                    Progress = 0                 });        });        //Practice        modelBuilder.Entity<Practice>(entity =>        {            entity.HasKey(e => e.PracticeId);            entity.HasOne(d => d.Install)                .WithOne(p => p.Practice)                .OnDelete(DeleteBehavior.ClientSetNull);
查看完整描述

1 回答

?
守著星空守著你

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊

EF Core 不會(huì)自動(dòng)包含相關(guān)對(duì)象。

您需要將其包含在您的查詢中

await?_context.Installs.Include(install?=>?install.Practice).ToListAsync();
查看完整回答
反對(duì) 回復(fù) 2023-06-25
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)