Last active
August 2, 2020 20:53
-
-
Save Beelzenef/7abe8569fa452a52a546cbac684d3e7d to your computer and use it in GitHub Desktop.
Proceso de crear una nueva entidad, 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
// 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(); | |
return result; | |
} | |
// Paso 2: Generación de un post que insertar | |
var newPost = new Post | |
{ | |
Title = "A new post", | |
Url = "URL", | |
Words = 300 | |
}; | |
// Paso 3: Llamada al método de creación | |
int postCreation = CreatePost(newPost); | |
if (postCreation == 1) | |
{ | |
Console.WriteLine($"Creación de post {newPost.Title} exitosa"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment