Subject | EF6 - Why extra index created? |
---|---|
Author | emel@emel.hu |
Post date | 2016-05-08T23:35:05Z |
I try the ordinary EF CodeFirst test with latest packages for new FB3.
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="EntityFramework.Firebird" version="4.10.0.0"
targetFramework="net452" />
<package id="FirebirdSql.Data.FirebirdClient" version="4.10.0.0"
targetFramework="net452" />
</packages>
---------------------
public class Blog
{
public int id { get; set; }
public string name { get; set; }
public DateTime created { get; set; }
public string comment { get; set; }
public virtual List<Post> posts { get; set; }
}
public class Post
{
public int id { get; set; }
public string content { get; set; }
public int blogId { get; set; }
public virtual Blog blog { get; set; }
}
....
public TestContext()
: base(connection, true)
{
}
public DbSet<Blog> Blog { get; set; }
public DbSet<Post> Posts { get; set; }
}
...
Database.SetInitializer(new MigrateDatabaseToLatestVersion<TestContext,
Configuration>());
-------------------------------------
This code creates this table definition:
CREATE TABLE "Posts"
(
"id" Integer NOT NULL,
"content" Blob sub_type 1,
"blogId" Integer NOT NULL,
CONSTRAINT "PK_Posts" PRIMARY KEY ("id")
);
ALTER TABLE "Posts" ADD CONSTRAINT "FK_Posts_Blogs_blogId"
FOREIGN KEY ("blogId") REFERENCES "Blogs" ("id") ON DELETE CASCADE;
CREATE INDEX "IX_Posts_blogId" ON "Posts" ("blogId");
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON "Posts" TO SYSDBA WITH GRANT OPTION;
----------------------------------------
BUT: why is created a "IX_Posts_blogId" index when the
"FK_Posts_Blogs_blogId" index created for FK?
eMeL
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="EntityFramework.Firebird" version="4.10.0.0"
targetFramework="net452" />
<package id="FirebirdSql.Data.FirebirdClient" version="4.10.0.0"
targetFramework="net452" />
</packages>
---------------------
public class Blog
{
public int id { get; set; }
public string name { get; set; }
public DateTime created { get; set; }
public string comment { get; set; }
public virtual List<Post> posts { get; set; }
}
public class Post
{
public int id { get; set; }
public string content { get; set; }
public int blogId { get; set; }
public virtual Blog blog { get; set; }
}
....
public TestContext()
: base(connection, true)
{
}
public DbSet<Blog> Blog { get; set; }
public DbSet<Post> Posts { get; set; }
}
...
Database.SetInitializer(new MigrateDatabaseToLatestVersion<TestContext,
Configuration>());
-------------------------------------
This code creates this table definition:
CREATE TABLE "Posts"
(
"id" Integer NOT NULL,
"content" Blob sub_type 1,
"blogId" Integer NOT NULL,
CONSTRAINT "PK_Posts" PRIMARY KEY ("id")
);
ALTER TABLE "Posts" ADD CONSTRAINT "FK_Posts_Blogs_blogId"
FOREIGN KEY ("blogId") REFERENCES "Blogs" ("id") ON DELETE CASCADE;
CREATE INDEX "IX_Posts_blogId" ON "Posts" ("blogId");
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON "Posts" TO SYSDBA WITH GRANT OPTION;
----------------------------------------
BUT: why is created a "IX_Posts_blogId" index when the
"FK_Posts_Blogs_blogId" index created for FK?
eMeL