Модель:
public class PriceList
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int ServiceId { get; set; }
[ForeignKey("ServiceId")]
public Service Service { get; set; }
public string Cost { get; set; }
}
Сохраняем:
public async Task<IEnumerable<PriceList>> CreatePriceList(IEnumerable<PriceList> priceList)
{
using (var context = ContextFactory.CreateDbContext(ConnectionString))
{
await context.PriceList.AddRangeAsync(priceList);
await context.SaveChangesAsync();
}
return priceList;
}
Из функции сохранения IEnumerable<PriceList> возвращается с Service = null. В бд все пишется. Так и должно быть, правильно?
Можно как-то без доп запроса к бд получить дочерние объекты?