C#
Asp.NetCoreApiのModel外部参照でNullが出る
出典: Asp.NetCoreApiのModel外部参照でNullを防ぐならIncludeを使え! — Asp.NetCoreApiのModel外部参照でNullが出る
namespace IncludeStudy.Models
{
public class Company
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Employee> Employees { get; set; }
public Company(int id, string name)
{
Id = id;
Name = name;
}
public Company()
{
}
}
}
▸ この snippet は実行結果未収録
▸ 実行結果は未収録です
Source収録記事
この snippet は記事の「Asp.NetCoreApiのModel外部参照でNullが出る」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。
同じ記事から
4 件namespace IncludeStudy.Models { public class Employee {未収録
Asp.NetCoreApiのModel外部参照でNullが出る
#77f64dbdbb38
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;未収録
Asp.NetCoreApiのModel外部参照でNullが出る
#87439b15ae9e
// GET: api/Companies/5 [HttpGet("{id}/emp")] public async Task<ActionResult<ICollection<Employee>>> GetCompanyEmp(int id) {未収録
Nullが出ないようにするにはIncludeを使う
#d7106e5aa49e
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers();未収録
JsonExceptionが出た場合は下記をする。
#7cf68e77babf
