Skip to content

Instantly share code, notes, and snippets.

View Beelzenef's full-sized avatar
📚
coding + learning

Elena.NET Beelzenef

📚
coding + learning
View GitHub Profile
@Beelzenef
Beelzenef / efcore_dbcontext_rels.cs
Last active August 24, 2020 08:23
Crear relación entre entidades, para medium.com/puntotech
using Microsoft.EntityFrameworkCore;
namespace PuntoTechApp
{
public class MyContext : DbContext
{
public DbSet<Posts> Posts { get; set; }
// Modificación: añadir colección de Authors
public DbSet<Authors> Authors { get; set; }
@Beelzenef
Beelzenef / efcore_updatepost.cs
Last active August 2, 2020 19:36
Proceso de actualizar entidad, para medium.com/puntotech
// Paso 1: Obtener una entidad por ID
private Post GetPost(int postToSearchId)
{
if (postToSearchId != 0)
{
IQueryable<Post> entitiesInSearch = ctx.Posts
.Where(p => p.Id == postToSearchId)
Post postToSearch = entitiesInSearch.SingleOrDefault()
return postToSearch;
@Beelzenef
Beelzenef / efcore_createpost.cs
Last active August 2, 2020 20:53
Proceso de crear una nueva entidad, para medium.com/puntotech
// Paso 1: Operación CREATE para la BD
private int CreatePost(Post newPost)
{
int result = 0
if (newPost != null)
{
ctx.Posts.Add(newPost);
result = ctx.SaveChanges();
@Beelzenef
Beelzenef / app_linq.cs
Last active August 24, 2020 08:25
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)
{
@Beelzenef
Beelzenef / initial_app.cs
Last active May 3, 2020 09:59
Ejemplo de aplicación de consola para medium.com/puntotech
using System;
namespace PuntoTechApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("¡Os damos la bienvenida a PuntoTechApp!");
@Beelzenef
Beelzenef / base_entity.cs
Created May 3, 2020 09:30
Entidad base para EF Core en medium.com/puntotech
namespace PuntoTechApp
{
public class BaseEntity
{
public int Id { get; set; }
}
}
@Beelzenef
Beelzenef / post_entity.cs
Created May 3, 2020 09:29
Entidad Post para EF Core en medium.com/puntotech
namespace PuntoTechApp
{
public class Post : BaseEntity
{
public string Title { get; set; }
public string Url { get; set; }
public int Words { get; set; }
}
}
@Beelzenef
Beelzenef / efcore_dbcontext_entities.cs
Last active June 10, 2020 18:24
Ejemplo de DbContext con entidades para medium.com/puntotech
using Microsoft.EntityFrameworkCore;
namespace PuntoTechApp
{
public class MyContext : DbContext
{
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
@Beelzenef
Beelzenef / efcore_dbcontext_conf.cs
Last active June 10, 2020 18:24
Ejemplo de DbContext para medium.com/puntotech
using Microsoft.EntityFrameworkCore;
namespace PuntoTechApp
{
public class MyContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
{
<StackPanel Padding="10"
Spacing="10">
<TextBlock Text="Windows" />
<StackPanel Orientation="Horizontal" Spacing="10" Padding="10">
<Button Content="Button" />
<Button Content="Button" IsEnabled="False" />
</StackPanel>
<TextBlock Text="iOS" />