Skip to content

Commit a41433d

Browse files
authored
Merge pull request #67 from msallin/topic/Issue-66
Topic/issue 66
2 parents 0223767 + e08bd22 commit a41433d

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.ObjectModel;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace SQLite.CodeFirst.Console.Entity
5+
{
6+
/// <summary>
7+
/// I agree, that this makes no sense.
8+
/// Its just to test the IsSelfReferencing method for table names which are shorter than 4 chars.
9+
/// See #66.
10+
/// </summary>
11+
public class Set
12+
{
13+
[Key]
14+
public string Title { get; set; }
15+
16+
public virtual Player Player { get; set; }
17+
}
18+
}

SQLite.CodeFirst.Console/FootballDbContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
1818
ConfigureStadionEntity(modelBuilder);
1919
ConfigureCoachEntity(modelBuilder);
2020
ConfigurePlayerEntity(modelBuilder);
21+
ConfigureSetEntity(modelBuilder);
2122

2223
var initializer = new FootballDbInitializer(modelBuilder);
2324
Database.SetInitializer(initializer);
@@ -56,5 +57,11 @@ private static void ConfigurePlayerEntity(DbModelBuilder modelBuilder)
5657
.WithMany(team => team.Players)
5758
.WillCascadeOnDelete(true);
5859
}
60+
61+
private static void ConfigureSetEntity(DbModelBuilder modelBuilder)
62+
{
63+
modelBuilder.Entity<Set>()
64+
.HasRequired(s => s.Player);
65+
}
5966
}
6067
}

SQLite.CodeFirst.Console/SQLite.CodeFirst.Console.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Compile Include="Entity\IEntity.cs" />
8181
<Compile Include="Entity\Person.cs" />
8282
<Compile Include="Entity\Player.cs" />
83+
<Compile Include="Entity\Set.cs" />
8384
<Compile Include="Entity\Stadion.cs" />
8485
<Compile Include="Entity\Team.cs" />
8586
<Compile Include="FootballDbContext.cs" />

SQLite.CodeFirst.Test/SQLite.CodeFirst.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<Compile Include="Statement\ColumnStatementTest.cs" />
9595
<Compile Include="Utility\ConnectionStringParserTest.cs" />
9696
<Compile Include="Utility\HashCreatorTest.cs" />
97-
<Compile Include="Utility\HistoryEntityTypeValidator.cs" />
97+
<Compile Include="Utility\HistoryEntityTypeValidatorTest.cs" />
9898
</ItemGroup>
9999
<ItemGroup>
100100
<Folder Include="Convention\" />

SQLite.CodeFirst/Internal/Utility/SqliteAssociationType.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ public SqliteAssociationType(AssociationType associationType, EntityContainer co
3636

3737
private static bool IsSelfReferencing(AssociationType associationType)
3838
{
39-
return associationType.Constraint.ToRole.Name.Remove(associationType.Constraint.ToRole.Name.Length - SelfReferencingPostfix.Length, SelfReferencingPostfix.Length) == associationType.Constraint.FromRole.Name;
39+
string to = associationType.Constraint.ToRole.Name;
40+
string from = associationType.Constraint.FromRole.Name;
41+
42+
if (to.Length <= SelfReferencingPostfix.Length)
43+
{
44+
return false;
45+
}
46+
47+
return to.Remove(to.Length - SelfReferencingPostfix.Length, SelfReferencingPostfix.Length) == from;
4048
}
4149

4250
public string ToRoleEntitySetName { get; set; }

0 commit comments

Comments
 (0)