-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
49 lines (41 loc) · 1.45 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using Blog.Models;
using Blog.Data;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
namespace Blog;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Vamos estudar Entity Framework!");
using var context = new BlogDataContext();
var user = new User{
Name = "Marcella Letícia A.S.A.",
Slug = "marcellaleticia-asa",
Email = "marcella@email.com.br",
Bio = "Dev Fullstack",
Image = "marcella-profile.jpg",
PasswordHash = "1234abc"
};
var category = new Category { Name = "Backend", Slug = "backend"};
var post = new Post {
Author = user,
Category = category,
Body = "<p>Teste</p>",
Slug = "comecando-com-ef-core",
Summary = "Vamos aprender sobre EF Core",
Title = "Entity Framework Core o agiliza sua vida!",
CreateDate = DateTime.Now,
LastUpdateDate = DateTime.Now
};
//context.Posts.AsNoTracking().OrderByDescending(x => x.LastUpdateDate).ToList().ForEach(x => Console.WriteLine(x.Title));
var postFound = context.Posts.Include(x => x.Author).FirstOrDefault();
if(postFound != null)
{
postFound.Author.Name = "Marcella 2";
context.SaveChanges();
}
}
}