Hi,
ich versuche mich gerade in das Thema Entity Framework einzuarbeiten (6.1.3).
Dazu habe ich mir eine kleine Anwendung erstellt. Jedoch hab ich scheinbar ein Problem die Verwendung einer lokalen SQLServer Datenbankdatei (*.mdf) zu verstehen.
Hier mal der Aufbau.
Projektmappe
Klassenprojekt (Bazaar.Core) Ordner Models
Seller.cs
Article.cs
Bazaar.Db
Ich habe dann eine Lokale SQLDatenbankdatei angelegt und ein Leeres EF Model hinzugefügt.
Die App.Config hat folgenden Connection String:
Danach habe ich die Migrations enabled und eine erste Migration angelegt:
InitialCreate
und dann ein Update-Database.
Das scheint ohne Fehler durch zu laufen, allerdings sehe ich im ServerExplorer keine Veränderung. es wird keine Tabelle angelegt.
Die Datenbankdatei steht auf "Immer kopieren".
Ich hänge das Projekt mal mit an.
Kann mir jemand kurz erklären, was ich falsch mache?
Danke Euch
Grüße
ich versuche mich gerade in das Thema Entity Framework einzuarbeiten (6.1.3).
Dazu habe ich mir eine kleine Anwendung erstellt. Jedoch hab ich scheinbar ein Problem die Verwendung einer lokalen SQLServer Datenbankdatei (*.mdf) zu verstehen.
Hier mal der Aufbau.
Projektmappe
Klassenprojekt (Bazaar.Core) Ordner Models
C#-Quellcode
- using System;
- using System.Collections.Generic;
- namespace Bazaar.Core.Models
- {
- public class Seller
- {
- public int ID { get; set; }
- public int SellerNo { get; set; }
- public string Name { get; set; }
- public decimal TurnOver { get; set; }
- public virtual ICollection<Article> Article { get; set; }
- public int CheckOutID { get; set; }
- public DateTime CheckOutDate { get; set; }
- public Seller()
- {
- Article = new HashSet<Article>();
- }
- }
- }
C#-Quellcode
- namespace Bazaar.Core.Models
- {
- public class Article
- {
- public int ID { get; set; }
- public int ArticleNo { get; set; }
- public string Matchcode { get; set; }
- public string Size { get; set; }
- public decimal Price { get; set; }
- public bool Sold { get; set; }
- public int SellerID { get; set; }
- public string SellerName { get; set; }
- }
- }
C#-Quellcode
- namespace Bazaar.Core.Models
- {
- using System.Data.Entity;
- public partial class BazaarDb : DbContext
- {
- public BazaarDb()
- : base("name=BazaarDb")
- {
- }
- public virtual DbSet<Seller> Sellers { get; set; }
- public virtual DbSet<Article> Articles { get; set; }
- public virtual DbSet<CheckOut> CheckOuts { get; set; }
- }
- }
Ich habe dann eine Lokale SQLDatenbankdatei angelegt und ein Leeres EF Model hinzugefügt.
Die App.Config hat folgenden Connection String:
XML-Quellcode
Danach habe ich die Migrations enabled und eine erste Migration angelegt:
C#-Quellcode
- namespace Bazaar.Core.Migrations
- {
- using System;
- using System.Data.Entity.Migrations;
- public partial class InitialCreate : DbMigration
- {
- public override void Up()
- {
- CreateTable(
- "dbo.Articles",
- c => new
- {
- ID = c.Int(nullable: false, identity: true),
- ArticleNo = c.Int(nullable: false),
- Matchcode = c.String(),
- Size = c.String(),
- Price = c.Decimal(nullable: false, precision: 18, scale: 2),
- Sold = c.Boolean(nullable: false),
- SellerID = c.Int(nullable: false),
- SellerName = c.String(),
- })
- .PrimaryKey(t => t.ID)
- .ForeignKey("dbo.Sellers", t => t.SellerID, cascadeDelete: true)
- .Index(t => t.SellerID);
- CreateTable(
- "dbo.CheckOuts",
- c => new
- {
- ID = c.Int(nullable: false, identity: true),
- BazaarDate = c.DateTime(nullable: false),
- })
- .PrimaryKey(t => t.ID);
- CreateTable(
- "dbo.Sellers",
- c => new
- {
- ID = c.Int(nullable: false, identity: true),
- SellerNo = c.Int(nullable: false),
- Name = c.String(),
- TurnOver = c.Decimal(nullable: false, precision: 18, scale: 2),
- CheckOutID = c.Int(nullable: false),
- CheckOutDate = c.DateTime(nullable: false),
- })
- .PrimaryKey(t => t.ID)
- .ForeignKey("dbo.CheckOuts", t => t.CheckOutID, cascadeDelete: true)
- .Index(t => t.CheckOutID);
- }
- public override void Down()
- {
- DropForeignKey("dbo.Sellers", "CheckOutID", "dbo.CheckOuts");
- DropForeignKey("dbo.Articles", "SellerID", "dbo.Sellers");
- DropIndex("dbo.Sellers", new[] { "CheckOutID" });
- DropIndex("dbo.Articles", new[] { "SellerID" });
- DropTable("dbo.Sellers");
- DropTable("dbo.CheckOuts");
- DropTable("dbo.Articles");
- }
- }
- }
und dann ein Update-Database.
Das scheint ohne Fehler durch zu laufen, allerdings sehe ich im ServerExplorer keine Veränderung. es wird keine Tabelle angelegt.
Die Datenbankdatei steht auf "Immer kopieren".
Ich hänge das Projekt mal mit an.
Kann mir jemand kurz erklären, was ich falsch mache?
Danke Euch
Grüße
"Hier könnte Ihre Werbung stehen..."