Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Naviagtion property to ApplicationUser comming back null

$
0
0

I no normally i must included the navigation property in my context return to the model I do not no what I enclude when using Idenity Application User.

When I try to access the property

  @notification.SharedFromUser.FirstNameI recieve a null error normally i no that is because I have not included it in my ef query.
 var test = await _context.MISobject.Include(C => C.StaffMembersOIC1).Include(c => c.StaffMembersOIC2).Include(c => c.MISPrioritys).ToListAsync();

So my main question is what does one enter in the include to link the user properly
As you see above i am using the .Include to ensure that my navigation property is linked.

This is my model decorations.

For If I try as below it is still null for that user.

private Task<List<Notifications>> GetItemsAsync(Guid userId) {
    return db.Notifications.Where(x => x.isActive ==true &&  x.DestinationUserId== userId || x.SharedFrom==userId.ToString()).Include(c => c.SharedToUser).Include(c=>c.SharedFromUser).ToListAsync();
        }

    [ForeignKey("SharedFromUser")]    public string? SharedFrom { get; set; }    public virtual ApplicationUser SharedFromUser { get; set; }




Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>