enter image description here creation
enter image description here models
enter image description here navigation property
enter image description here dbset making
enter image description here scaffolded itmes creation
enter image description here dto creation
enter image description here put endpoint changes
here is a code for that:
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<IngatlanContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
var app = builder.Build();
--------------------------------
public class IngatlanContext : DbContext
{
public IngatlanContext(DbContextOptions<IngatlanContext> options) : base(options)
{
}
public DbSet<Ingatlan> Ingatlanok { get; set; } = null!;
public DbSet<Kategoria> Kategoriak { get; set; } = null!;
}
--------------------------------
public class IngatlanGetDto
{
public int Id { get; set; }
public string? Leiras { get; set; }
public DateTime HirdetesKezdete { get; set; }
public DateTime HirdetesVege { get; set; }
public int Ar { get; set; }
public bool Hitelkepes { get; set; }
public string? KategoriaNeve { get; set; }
}
--------------------------------
Kategoria (1) - Ingatlan (N)
N:
[ForeignKey("KategoriaId")]
public Kategoria? Kategoria { get; set; }
1:
[JsonIgnore]
public List<Ingatlan>? Ingatlanok { get; set; }