12
I’m studying C# and I just made my first query in the Database:
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 like 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 didn’t get to look at any tutorial, but I was trying to make the query "lucky" and I ended up getting.
I understood so far that in the method Where
is expected to pass a lambda
. Another thing I understood is that the expression that returns true
inside will be the data that will be returned from the table.
But then some doubts arose:
Whenever I want to use one
Where
, I just do something equivalent (ie, what I would do in theMysql
, translating toC#
) within thatlambda
returningtrue
orfalse
for the data I want to return?If I wanted users who didn’t have the word
Wallace
, would suffice to "deny" theContains
?If the
Where
needs only onetrue
orfalse
returned bylambda
, how does theEntity Framework
can use C# Syntax to queryMysql
?
This last paragraph that talks about Visual Studio ... My machine is linux, I can only use Monodevelop... Sniff
– Wallace Maxters
Then I don’t know if there’s anything that helps. Although you can develop C# on Linux, the experience is much lower.
– Maniero
Well, I guess at least my virtual box can save me :)
– Wallace Maxters
Visual Studio in VM? Good luck :)
– Maniero
@bigown ever tried to use VS in VM ? just curious why I would try it next week on vacation, it doesn’t work?
– PauloHDSousa
No, but he’s pretty heavy, this isn’t gonna work. It will work, of course, but get a crank, especially if the machine isn’t a 10 and the VM doesn’t get almost all the memory for it.
– Maniero
@bigown thank you very much, I will install 2 S.O. vlw.
– PauloHDSousa
@Wallacemaxters, another alternative is to use the
.NET Core
with the Visual Studio Code as IDE.– Tobias Mesquita
@Tobymosque, thanks... It helped my ass. I’ll take a look here
– Wallace Maxters
VS Code does not compare to VS.
– Maniero
I asked that question @Tobymosque http://answall.com/questions/125949/alterativas-para-development-em-c-no-linux
– Wallace Maxters
@bigown, without a shadow of a doubt, but speaking of Linux, VS is not an option, I just meant that the
.NET Code
withVS Code
is an option toMono
with theMonoDeveloper
to develop cross-platform applications using.NET Framework
.– Tobias Mesquita
Relax, guys. I already installed Windows 10 on my :D machine
– Wallace Maxters