Dbinitializer.cs 1.63 KB
Newer Older
Nikita Kums's avatar
1  
Nikita Kums committed
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
using System.Linq;
using DAL;
using Domain;

namespace ConsoleApp
{
    public static class Dbinitializer
    {
        public static void initialize(this DbContext dbContext)
        {
            dbContext.ContactTypes.Add(new ContactType("Discord"));
            dbContext.Persons.Add(new Person("test1", "test1"));
            dbContext.Persons.Add(new Person("Kati", "REE"));
            dbContext.Contacts.Add(
                new Contact(
                    "KatiR", 
                    dbContext.Persons.First(p => p.FirstName == "Kati" && p.LastName == "REE"), 
                    dbContext.ContactTypes.First(c => c.ContactTypeValue == "Discord")
                ));
            // Func<parameter0, p1, ..., p16, returnType> -
            // give me an method, with p0-pxx parameters (can be none) and return me returnTpe value
            /*
             *                Same as the p => ... lambda expression
             * 
             * db.Context.Persons.First(p => IsPerson(p, "Kati", "REE"))
             *
             * static void bool IsPerson(Person person, string firstName, string lastName){
             *     if (person.FirstName == firstName && person.LastName == lastName) return true;
             *     return false
             * }
             *
             *                Same thing, different implementation
             * 
             * db.Context.Persons.First(IsPerson)
             * 
             * static static bool IsPerson(Person person){
             *     if (person.FirstName == firstName && person.LastName == lastName) return true;
             *     return false
             * }
             */
        }
    }
}