Hello, I'm trying to make a ToDo List on Asp.net 5.
There are two models with a one-to-many connection.
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; namespace tdl_api.Models { public class Reminder { [Key] public long Id { get; set; } public string Title { get; set; } public DateTime? Create_date { get; set; } public string Body { get; set; } public bool Status { get; set; } public long? TypeId { get; set; } public virtual Type Type { get; set; } } } using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; namespace tdl_api.Models { public class Type { [Key] public long Id { get; set; } public string Name { get; set; } public virtual ICollection<Reminder> Reminders { get; set; } public Type() { Reminders = new HashSet<Reminder>(); } } } Also data context
using Microsoft.Data.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace tdl_api.Models { public class Contex: DbContext { public DbSet<Reminder> reminders { get; set; } public DbSet<Type> types { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Reminder>(e => { e.HasOne(r => r.Type).WithMany(t => t.Reminders); }); base.OnModelCreating(modelBuilder); } } } In the repository I get this:
List<Reminder> data = await _db.reminders.ToListAsync(); But in Reminder objects, all Type is null (not pull-up). What missed? Did about how here.
Include()i.e. obviously load the necessary entities? PS: Entity Framework 7 has not yet felt, but at 6 it works like this - Bald