Skip to content

Instantly share code, notes, and snippets.

@Beelzenef
Last active August 2, 2020 20:53
Show Gist options
  • Save Beelzenef/7abe8569fa452a52a546cbac684d3e7d to your computer and use it in GitHub Desktop.
Save Beelzenef/7abe8569fa452a52a546cbac684d3e7d to your computer and use it in GitHub Desktop.
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();
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