I'm studying C # and just did my first query in the Data Bank:
using System;
using System.Data.Entity.Core;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Test.Models
{
[Table("usuarios")]
public class Usuario
{
[Key]
public int Id{ set; get; }
public string Username {
set;
get;
}
public string Password {
set;
get;
}
public string Nome {
set;
get;
}
}
}
In my Controller
I do this:
var context = new SimpleContext ();
ViewBag.title = "Página inicial";
var usuarios = context.Usuarios
.Where ((usuario) => usuario.Nome.Contains ("wallace"))
.OrderBy((usuario) => usuario.Nome)
.Take (10)
.ToList ();
return View (usuarios);
I did not get to look at any tutorial, but I tried to make the query "in luck" and I ended up getting it.
I have understood so far that in the Where
method it is expected to pass lambda
. Another thing I understand is that the expression that returns true
in there will be the data that will be returned from the table.
But here some doubts have arisen:
-
Whenever I want to use
Where
, I just do something equivalent (that is, what I would do inMysql
, translating toC#
) within thatlambda
returningtrue
or% how do I get the data I want to return? -
If I wanted users who did not have the word
false
, would it suffice to "deny"Wallace
? -
If
Contains
only needs aWhere
ortrue
returned byfalse
, how canlambda
be able to use C # Syntax to queryEntity Framework
?