Skip to content

Commit

Permalink
Merge pull request #77 from rwasef1830/fix_72
Browse files Browse the repository at this point in the history
Ignore empty schema string. Fixes #72. (original pull request: #75).
  • Loading branch information
rwasef1830 authored Sep 10, 2017
2 parents 8772228 + 42393c1 commit a2ed59f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
23 changes: 19 additions & 4 deletions src/EntityFramework6.Npgsql/SqlGenerators/SqlBaseGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,27 @@ public override VisitedExpression Visit([NotNull] DbScanExpression expression)
ScanExpression scan;
var overrideSchema = "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Schema";
if (expression.Target.MetadataProperties.TryGetValue(overrideSchema, false, out metadata) && metadata.Value != null)
scan = new ScanExpression(QuoteIdentifier(metadata.Value.ToString()) + "." + QuoteIdentifier(tableName), expression.Target);
{
var schema = metadata.Value.ToString();
scan = string.IsNullOrEmpty(schema)
? new ScanExpression(QuoteIdentifier(tableName), expression.Target)
: new ScanExpression(QuoteIdentifier(schema) + "." + QuoteIdentifier(tableName), expression.Target);
}
else if (expression.Target.MetadataProperties.TryGetValue("Schema", false, out metadata) && metadata.Value != null)
scan = new ScanExpression(QuoteIdentifier(metadata.Value.ToString()) + "." + QuoteIdentifier(tableName), expression.Target);
{
var schema = metadata.Value.ToString();
scan = string.IsNullOrEmpty(schema)
? new ScanExpression(QuoteIdentifier(tableName), expression.Target)
: new ScanExpression(QuoteIdentifier(schema) + "." + QuoteIdentifier(tableName), expression.Target);
}
else
scan = new ScanExpression(QuoteIdentifier(expression.Target.EntityContainer.Name) + "." + QuoteIdentifier(tableName), expression.Target);

{
var schema = expression.Target.EntityContainer.Name;
scan = string.IsNullOrEmpty(schema)
? new ScanExpression(QuoteIdentifier(tableName), expression.Target)
: new ScanExpression(QuoteIdentifier(schema) + "." + QuoteIdentifier(tableName), expression.Target);
}

return scan;
}

Expand Down
25 changes: 23 additions & 2 deletions test/EntityFramework6.Npgsql.Tests/EntityFrameworkBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ public void InsertAndSelect()
}
}

[Test]
public void InsertAndSelectSchemaless()
{
using (var context = new BloggingContext(ConnectionString))
{
context.Database.Delete();
context.Database.Create();
}

using (var context = new BloggingContext(ConnectionString))
{
context.NoColumnsEntities.Add(new NoColumnsEntity());
context.SaveChanges();
}

using (var context = new BloggingContext(ConnectionString))
{
Assert.AreEqual(1, context.NoColumnsEntities.Count());
}
}

[Test]
public void SelectWithWhere()
{
Expand Down Expand Up @@ -621,8 +642,8 @@ public void TestScalarValuedStoredFunctions()
CollectionAssert.AreEqual(localChangedIds, remoteChangedIds);
}
}
[Test]
[Test]
public void TestScalarValuedStoredFunctions_with_null_StoreFunctionName()
{
using (var context = new BloggingContext(ConnectionString))
Expand Down

0 comments on commit a2ed59f

Please sign in to comment.