TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
RobertoCarlos Melgar
1.5k
159
9.3k
get UserId and nameId with Entity Framework login
Apr 25 2020 2:00 PM
Good afternoon, I am working with Entity Framework, C # and Sql server, in a project, I have this method for login, which works correctly.
public
static
bool
ValidarUsuario(
string
Usuario,
string
Password)
{
using
(GourmetEntities db =
new
GourmetEntities())
{
// bcryp para encriptar, buscar información
var Usu = from u
in
db.tblUsuarios
where u.Usuario == Usuario && u.Password == Password
select
new
{ u.Usuario,u.Perfil_Id};
if
(Usu.Count() > 0)
{
return
true
;
}
else
{
return
false
;
}
}
}
but after that I need to get the UserId, UserName, and profileId to perform other operations, and I would like to save them in session variables, please how can I do that, since the return of my method is bool. This is the code of my button
private
void
BtnIngresar_Click(
object
sender, EventArgs e)
{
if
(CapaDatos.tblUsuario.ValidarUsuario(TxtUsuario.Text, TxtPassword.Text))
{
FrmPadre frmPadre =
new
FrmPadre();
frmPadre.Show();
}
else
{
return
;
}
}
Now with Entity Framework and linq I generate this sql server code which brings me the data I need,
but I don't know how to get it in c #
declare
@p__linq__0
varchar
(30)
set
@p__linq__0 =
'rmelgar'
;
declare
@p__linq__1
varchar
(30)
set
@p__linq__1 =
'123456789sc'
;
SELECT
1
AS
[C1],
[Extent1].[Usuario]
AS
[Usuario],
[Extent1].[Perfil_Id]
AS
[Perfil_Id]
FROM
[dbo].[tblUsuarios]
AS
[Extent1]
WHERE
([Extent1].[Usuario] = @p__linq__0)
AND
([Extent1].[
Password
] = @p__linq__1)
Please can you help me solve my problem, thank you very much
Please excuse me, I still don't know how to use the forum, I think I have formats that should not be
Roberto
Reply
Answers (
8
)
C# procula to Calculated on the type of the account and the
how to filter list<string> elements=new list<string>