简体   繁体   中英

Join table in Entity framework

I'll have this query in joining the table but it did not returned data from Include table or Join table.

var tasks = (from item in ctx.Tasks
             join tp in ctx.TaskPlugins
             on item.TaskId equals tp.TaskId
             select item)
              .Include(x => x.TaskPlugins).Include(x => x.TaskPlugins.Select(p => p.Plugin)).Include(x=>x.TaskPlugins.Select(p=>p.Plugin.Store));
return ctx.Tasks.ToList();

But this query does not return data from TaskPlugins 屏幕截图

Error Message: ((System.Data.Entity.DynamicProxies.Task_6F777A6C52D9E84FD3DF53481564A61969CE62ABBA9D985448F99BFB8A49A2D7)new System.Collections.Generic.Mscorlib_CollectionDebugView<oRouter.Model.Task>(task).Items[0]).TaskPlugins

Thanks.

One thing, You should be returning tasks.ToList() and not ctx.Tasks.ToList()

Second, the last include .Include(x=>x.TaskPlugins.Select(p=>p.Plugin.Store) is the only one needed. First 2 includes are NOT needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM