예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ProduktContext produktContext)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            //anschriftGeschaeftContext.Database.EnsureCreated();
            //anschriftHerstellerContext.Database.EnsureCreated();
            produktContext.Database.EnsureCreated();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Produkt p1 = new Produkt()
            {
                Bezeichnung = "Tastatur", Preis = 50, Kategorie = "IT"
            };

            ProduktContext ctx = new ProduktContext();

            ctx.MeineProdukte.Add(p1);

            ctx.SaveChanges(); //Speichert das neue Produkt in der DB
        }
예제 #3
0
 public KategorisController(ProduktContext context)
 {
     _context = context;
 }
 public HerstellersController(ProduktContext context)
 {
     _context = context;
 }
예제 #5
0
 public GeschaeftsController(ProduktContext context)
 {
     _context = context;
 }
예제 #6
0
        static void Main(string[] args)
        {
            Produkt p = new Produkt()
            {
                Bezeichnung = "Kugelschreiber", Kategorie = "Schreibwaren"
            };

            ProduktContext ctx = new ProduktContext();

            //Insert
            //  ctx.Produkte.Add(p);
            //  ctx.SaveChanges();// "c:\users\johann.grabner\ProduktContext.mdf"

            //Serverexplorer - DAtenverbindungen -
            //Verbindung hinzufügen - SQL Server Datenbnakdatei
            //Löschen, Suchen und ändern
            //11:15 Uhr -- EF & CRUD

            //alle Datensätze auslesen

            //select
            foreach (Produkt produkt in ctx.Produkte)
            {
                Console.WriteLine($"Bez: {produkt.Bezeichnung} Kat {produkt.Kategorie}");
            }

            //Filtern von Daten
            //select ... WHERE Bezeichnung='Kugelschreiber'
            IQueryable <Produkt> ergebnisV1 =
                ctx.Produkte.Where(pr => pr.Bezeichnung == "Kugelschreiber");

            //Compiler ermittelt Datentyp aus der rechten Zuweisung
            var ergebnisV2 = ctx.Produkte.Where(pr => pr.Bezeichnung == "Kugelschreiber");

            Console.WriteLine("Alle Kugelschreiber");
            foreach (var prod in ergebnisV1)
            {
                Console.WriteLine($"Bez: {prod.Bezeichnung}");
            }

            //select... WHERE ProduktId = 1
            var produktMitPK1 = ctx.Produkte.Find(1);

            if (produktMitPK1 != null)
            {
                Console.WriteLine($"Bez: {produktMitPK1.Bezeichnung}");
            }

            //DML - Update
            //Update Produkte set Bezeichnung='Füllfeder'
            //where ProduktId=2
            //1. Holen der Entity
            //2. Update der Properties "lokal" - im Program
            //3. SaveChanges

            var productToChange = ctx.Produkte.Find(2);

            productToChange.Bezeichnung = "Füllfeder";
            productToChange.Kategorie   = "Schreibgerät";
            ctx.SaveChanges(); //Change-Tracker

            //DML - Delete
            //DELET FROM Produkte where ProduktId=2
            //1. Holen der Entity
            //2. Remove
            //3. SaveChanges

            var productToDelete = ctx.Produkte.Find(2);

            ctx.Produkte.Remove(productToDelete);
            ctx.SaveChanges();
        }
예제 #7
0
 public DaneBazaModel(ILogger <DaneBazaModel> logger, ProduktContext context)
 {
     _logger  = logger;
     _context = context;
 }
예제 #8
0
 public PreiseController(ProduktContext context)
 {
     _context = context;
 }