Skip to content

Commit a2ed59f

Browse files
authored
Merge pull request #77 from rwasef1830/fix_72
Ignore empty schema string. Fixes #72. (original pull request: #75).
2 parents 8772228 + 42393c1 commit a2ed59f

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/EntityFramework6.Npgsql/SqlGenerators/SqlBaseGenerator.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,12 +553,27 @@ public override VisitedExpression Visit([NotNull] DbScanExpression expression)
553553
ScanExpression scan;
554554
var overrideSchema = "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Schema";
555555
if (expression.Target.MetadataProperties.TryGetValue(overrideSchema, false, out metadata) && metadata.Value != null)
556-
scan = new ScanExpression(QuoteIdentifier(metadata.Value.ToString()) + "." + QuoteIdentifier(tableName), expression.Target);
556+
{
557+
var schema = metadata.Value.ToString();
558+
scan = string.IsNullOrEmpty(schema)
559+
? new ScanExpression(QuoteIdentifier(tableName), expression.Target)
560+
: new ScanExpression(QuoteIdentifier(schema) + "." + QuoteIdentifier(tableName), expression.Target);
561+
}
557562
else if (expression.Target.MetadataProperties.TryGetValue("Schema", false, out metadata) && metadata.Value != null)
558-
scan = new ScanExpression(QuoteIdentifier(metadata.Value.ToString()) + "." + QuoteIdentifier(tableName), expression.Target);
563+
{
564+
var schema = metadata.Value.ToString();
565+
scan = string.IsNullOrEmpty(schema)
566+
? new ScanExpression(QuoteIdentifier(tableName), expression.Target)
567+
: new ScanExpression(QuoteIdentifier(schema) + "." + QuoteIdentifier(tableName), expression.Target);
568+
}
559569
else
560-
scan = new ScanExpression(QuoteIdentifier(expression.Target.EntityContainer.Name) + "." + QuoteIdentifier(tableName), expression.Target);
561-
570+
{
571+
var schema = expression.Target.EntityContainer.Name;
572+
scan = string.IsNullOrEmpty(schema)
573+
? new ScanExpression(QuoteIdentifier(tableName), expression.Target)
574+
: new ScanExpression(QuoteIdentifier(schema) + "." + QuoteIdentifier(tableName), expression.Target);
575+
}
576+
562577
return scan;
563578
}
564579

test/EntityFramework6.Npgsql.Tests/EntityFrameworkBasicTests.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ public void InsertAndSelect()
8282
}
8383
}
8484

85+
[Test]
86+
public void InsertAndSelectSchemaless()
87+
{
88+
using (var context = new BloggingContext(ConnectionString))
89+
{
90+
context.Database.Delete();
91+
context.Database.Create();
92+
}
93+
94+
using (var context = new BloggingContext(ConnectionString))
95+
{
96+
context.NoColumnsEntities.Add(new NoColumnsEntity());
97+
context.SaveChanges();
98+
}
99+
100+
using (var context = new BloggingContext(ConnectionString))
101+
{
102+
Assert.AreEqual(1, context.NoColumnsEntities.Count());
103+
}
104+
}
105+
85106
[Test]
86107
public void SelectWithWhere()
87108
{
@@ -621,8 +642,8 @@ public void TestScalarValuedStoredFunctions()
621642
CollectionAssert.AreEqual(localChangedIds, remoteChangedIds);
622643
}
623644
}
624-
625-
[Test]
645+
646+
[Test]
626647
public void TestScalarValuedStoredFunctions_with_null_StoreFunctionName()
627648
{
628649
using (var context = new BloggingContext(ConnectionString))

0 commit comments

Comments
 (0)