Last active
August 24, 2020 08:25
-
-
Save Beelzenef/69fcb317118899e7453582bbcd642e56 to your computer and use it in GitHub Desktop.
Ejemplo de LINQ, para medium.com/puntotech
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
// Paso 1: Referencia a Linq para poder usarlo en nuestro software | |
using System.Linq; | |
namespace PuntoTechApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("¡Os damos la bienvenida a PuntoTechApp!"); | |
Console.WriteLine("Nuestros posts publicados son..."); | |
// Paso 2: Creando instancia | |
var ctx = new MyContext(); | |
// Paso 3: Acceso a la tabla Posts y conversión a List de Posts | |
var posts = ctx.Posts.ToList(); | |
// Paso 4: Si hay elementos para iterar, los mostramos por pantalla | |
if (posts.Count > 0) | |
{ | |
foreach (var post in posts) | |
{ | |
Console.WriteLine($"Post {post.Title} con {post.Words.ToString()} palabras"); | |
} | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment