Skip to content

Commit e308041

Browse files
committed
Support for Table Annotation.
1 parent 3ea43ca commit e308041

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

SQLite.CodeFirst.Console/Entity/Player.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace SQLite.CodeFirst.Console.Entity
1+

2+
namespace SQLite.CodeFirst.Console.Entity
23
{
34
public class Player : IEntity
45
{

SQLite.CodeFirst.Console/TestDbContext.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Data.Entity;
1+
using System;
2+
using System.Data.Entity;
3+
using System.Data.Entity.ModelConfiguration.Configuration;
24
using System.Data.Entity.ModelConfiguration.Conventions;
35
using SQLite.CodeFirst.Console.Entity;
46

@@ -33,6 +35,8 @@ private static void ConfigurePlayerEntity(DbModelBuilder modelBuilder)
3335
modelBuilder.Entity<Player>().HasKey(player => player.Id);
3436
modelBuilder.Entity<Player>().Property(player => player.Name).HasMaxLength(10);
3537

38+
modelBuilder.Entity<Player>().ToTable("TeamPlayer");
39+
3640
modelBuilder.Entity<Player>()
3741
.HasRequired(p => p.Team)
3842
.WithMany(team => team.Players)

SQLite.CodeFirst/Builder/CreateTableStatementBuilder.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,20 @@ public CreateTableStatement BuildStatement()
2727

2828
return new CreateTableStatement
2929
{
30-
TableName = entityType.Name,
30+
TableName = GetTableName(),
3131
ColumnCollection = columnCollection
3232
};
3333
}
34+
35+
private string GetTableName()
36+
{
37+
MetadataProperty metadataProperty;
38+
if (entityType.MetadataProperties.TryGetValue("TableName", false, out metadataProperty))
39+
{
40+
return metadataProperty.Value.ToString();
41+
}
42+
43+
return entityType.Name;
44+
}
3445
}
3546
}

0 commit comments

Comments
 (0)