Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've added to fields to the AspNetUsers table, the two fields (LastName and FirstName) appear in the database as expected. When I try to get the values in these two fields I receive red lines under the field names and error message indicating the fields cannot be found. What query will return the values. I can get the logged-in UserName, and I filter the query with it.

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using FSA.Data;
using FSA.Models;
using Microsoft.AspNetCore.Identity;

namespace FSA.Pages.Activities
{
    public class IndexModel : PageModel
    {
        private readonly FSA.Data.ApplicationDbContext _context;

        public IndexModel(FSA.Data.ApplicationDbContext context)
        {
            _context = context;
        }

        public IList<activity> Activity { get; set; }

        public async Task OnGetAsync()
        {

            // get user's Name (email address) from Identity (dbo.AspNetUsers)
            string userName = User.Identity.Name;

            // get users last and first name (fname) from Identity with userName as a filter
            var pubNameQuery = from n in _context.Users.AsNoTracking()
                               where n.UserName == userName
                               select n.LastName + ", " + n.FirstName;

            string fname = await pubNameQuery.SingleAsync();

        }
    }
}
Posted
Updated 5-Feb-19 3:26am
v2
Comments
MadMyche 30-Jan-19 19:51pm    
Did you update the Entity within your project to reflect the new DB fields?
Member 8668966 31-Jan-19 18:09pm    
Yes.
Bryian Tan 5-Feb-19 9:41am    
try delete the user entity from the edmx and re-add again (assuming database first)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900