linq query not returning anything by itself but data shows when there is a join added. What am I doing wrong?

211 Views Asked by At

No idea how to troubleshoot this but returns nothing even though there is data in the table

  var quickLinks = from ql in _ctx.QuickLinks
                             
                             select new QuickLinksViewModel
                             {                                    
                                 ItemId = ql.ItemID,
                                 ItemGuid = ql.ItemGUID,
                                 UserId = ql.UserId,
                                 Computerid = ql.Computerid,
                                 Docid = ql.Docid,
                                 CustomLinkUrl = ql.CustomLinkUrl,
                                 CustomLinkText = ql.CustomLinkText,
                                 LinkOrder = ql.LinkOrder,
                                 CustomLinkTarget = ql.CustomLinkTarget                                     
                             };
       return quickLinks;

but when I add this join it pulls the data

  var quickLinks = from ql in _ctx.QuickLinks
                             join cd in _ctx.CMSDocument
                             on ql.Docid equals cd.DocumentID                                 
                             select new QuickLinksViewModel
                             {                                     
                                 ItemId = ql.ItemID,
                                 ItemGuid = ql.ItemGUID,
                                 UserId = ql.UserId,
                                 Computerid = ql.Computerid,
                                 Docid = ql.Docid,
                                 CustomLinkUrl = ql.CustomLinkUrl,
                                 CustomLinkText = ql.CustomLinkText,
                                 LinkOrder = ql.LinkOrder,
                                 CustomLinkTarget = ql.CustomLinkTarget                                     
                             };
       return quickLinks;

where am I going wrong?

1

There are 1 best solutions below

0
Lawrence Whittemore On

So I figured it out. The issue was I had an int in my entity that was not defined as nullable.

public Nullable<int> DocId { get; set; }