Skip to content

Instantly share code, notes, and snippets.

@Beelzenef
Last active August 24, 2020 08:25
Show Gist options
  • Save Beelzenef/69fcb317118899e7453582bbcd642e56 to your computer and use it in GitHub Desktop.
Save Beelzenef/69fcb317118899e7453582bbcd642e56 to your computer and use it in GitHub Desktop.
Ejemplo de LINQ, para medium.com/puntotech
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