c# - Linq Query not returning value from database field -


i literally have no idea why isn't querying way expect query, new programming in head seems right.

i using this.context.user.identity.name return logged in user returns email not username. here script in it's context.

@html.actionlink("my account", "users", new { id = this.context.user.identity.name  },     false) @: | @html.actionlink("logout", "logout", "users")  

from want url website/users/username hence wanting username instead of email.

the query:

project1.models.dbcontext db = new project1.models.dbcontext(); //save u.username in var user u.email == user_logged_in_email  var user = u in db.users            u.email == this.context.user.identity.name            select u.username; 

i hoping linq query find row contained email address , pull username out , store in var user. equals system.data.entity.infrastructure.dbquery

you need enumerate query user:

var user = (from u in db.users            u.email == this.context.user.identity.name            select u.username).singleordefault(); //singleordefault return null if no user found, need check before operating upon user object. 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -