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())
- {
-
- 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