コード例 #1
0
ファイル: Program.cs プロジェクト: nimartin/Exemples
        // permet de tester EF avec les DataAnnotations
        public static void TestEFAvecDataAnnotations()
        {
            // test du contexte avec data annotation
            ContextDA contexteDA = new ContextDA();

            // ajout d'un nouveau client avec un compte
            List <ModeleDA.CompteClient> comptes = new List <ModeleDA.CompteClient>();

            comptes.Add(new ModeleDA.CompteClient {
                NomBanque = "CA", NumeroCompte = "1234"
            });
            contexteDA.Clients.Add(new ModeleDA.Client {
                Nom = "TEST", Comptes = comptes
            });
            contexteDA.SaveChanges();

            // lecture des clients
            List <ModeleDA.Client> mesClients = contexteDA.Clients.Include(c => c.Comptes).ToList();

            Console.WriteLine("Liste de mes clients avec DA : ");
            foreach (ModeleDA.Client c in mesClients)
            {
                Console.WriteLine("Client n°{0} : {1}", c.Id, c.Nom);
                foreach (ModeleDA.CompteClient cc in c.Comptes)
                {
                    Console.WriteLine("|__ Compte n°{0}", cc.NumeroCompte);
                }
            }
            Console.WriteLine("...Fin...");
        }
コード例 #2
0
ファイル: CustomerTest.cs プロジェクト: dbousfira/.NET
        public void TestMethod1()
        {
            // Create and save a new Customer
            Customer c = new Customer("Toto");

            db.Customers.Add(c);
            db.SaveChanges();

            // Display all Blogs from the database
            IEnumerable <Customer> query = from customer in db.Customers
                                           orderby customer.LastName
                                           select customer;

            Console.WriteLine("All customers in the database:");
            foreach (var item in query)
            {
                Console.WriteLine(item.LastName);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
コード例 #3
0
ファイル: ProductCommand.cs プロジェクト: dbousfira/.NET
 public int Create(Product p)
 {
     _context.Products.Add(p);
     return(_context.SaveChanges());
 }
コード例 #4
0
 public bool addEmployee(Employee employee)
 {
     contexte.Employees.Add(employee);
     contexte.SaveChanges();
     return(true);
 }
コード例 #5
0
 /// <summary>
 /// Ajouter le status en base à partir du contexte
 /// </summary>
 /// <param name="o">Offre à ajouter</param>
 /// <returns>Identifiant du offre ajouté</returns>
 public int Ajouter(Status s)
 {
     _contexte.Statuses.Add(s);
     return(_contexte.SaveChanges());
 }
コード例 #6
0
 /// <summary>
 /// Ajouter l'offre en base à partir du contexte
 /// </summary>
 /// <param name="o">Offre à ajouter</param>
 /// <returns>Identifiant de l'offre ajouté</returns>
 public int Add(Offer o)
 {
     _contexte.Offers.Add(o);
     return(_contexte.SaveChanges());
 }