Here is my test project: https://github.com/pavelzazulia/FxNet.Web.Def.Api.Diagnostic
Spent huge of time but do not understand why .Include(t => t.Nodes)
does not return referenced entities:
public class TreeRepository : ITreeRepository
{
private DataBaseContext dataBaseContext;
public TreeRepository(DataBaseContext dataBaseContext)
{
this.dataBaseContext = dataBaseContext;
}
public async Task<ITree> GetTreeAsync(string name)
{
var tree = dataBaseContext.Tree.Include(t => t.Nodes).SingleOrDefault(t => t.Name == name);
if (tree == null)
{
var t = await dataBaseContext.Tree.AddAsync(new TreeTable { Name = name });
await dataBaseContext.SaveChangesAsync();
tree = t.Entity;
}
return tree;
}
}
.Include(t => t.Nodes)
should return nodes entities if they exist
New contributor
Pavel Zazulia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1