-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from NorthernLight1/development
Add Support For Table-Per-Concrete Inheritance
- Loading branch information
Showing
27 changed files
with
758 additions
and
732 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
N.EntityFrameworkCore.Extensions.Test/Data/SqlExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Runtime.InteropServices.ObjectiveC; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N.EntityFrameworkCore.Extensions.Sql | ||
{ | ||
internal class SqlExpression | ||
{ | ||
SqlExpressionType ExpressionType { get; } | ||
List<object> Items { get; set; } | ||
string Sql => ToSql(); | ||
string Alias { get; } | ||
bool IsEmpty => Items.Count == 0; | ||
|
||
internal SqlExpression(SqlExpressionType expressionType, object item, string alias = null) | ||
{ | ||
ExpressionType = expressionType; | ||
Items = new List<object>(); | ||
if (item is IEnumerable<string> values) | ||
{ | ||
Items.AddRange(values.ToArray()); | ||
} | ||
else | ||
{ | ||
Items.Add(item); | ||
} | ||
Alias = alias; | ||
} | ||
internal SqlExpression(SqlExpressionType expressionType, object[] items, string alias = null) | ||
{ | ||
ExpressionType = expressionType; | ||
Items = new List<object>(); | ||
Items.AddRange(items); | ||
Alias = alias; | ||
} | ||
internal static SqlExpression Columns(IEnumerable<string> columns) | ||
{ | ||
return new SqlExpression(SqlExpressionType.Columns, columns); | ||
} | ||
|
||
internal static SqlExpression String(string joinOnCondition) | ||
{ | ||
return new SqlExpression(SqlExpressionType.String, joinOnCondition); | ||
} | ||
|
||
internal static SqlExpression Table(string tableName, string alias = null) | ||
{ | ||
return new SqlExpression(SqlExpressionType.Table, tableName, alias); | ||
} | ||
|
||
private string ToSql() | ||
{ | ||
var values = Items.Select(o => o.ToString()).ToArray(); | ||
StringBuilder sbSql = new StringBuilder(); | ||
if (ExpressionType == SqlExpressionType.Columns) | ||
{ | ||
sbSql.Append(string.Join(",", values.Select(c => c.StartsWith("$") || c.StartsWith("[") ? c : $"[{c}]"))); | ||
} | ||
else | ||
{ | ||
sbSql.Append(string.Join(",", Items.Select(o => o.ToString()))); | ||
} | ||
if (Alias != null) | ||
{ | ||
sbSql.Append(" "); | ||
sbSql.Append(SqlKeyword.As.ToString().ToUpper()); | ||
sbSql.Append(" "); | ||
sbSql.Append(Alias); | ||
} | ||
//var test = Items.Select(o => o.ToString()).ToArray(); | ||
return sbSql.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace N.EntityFrameworkCore.Extensions.Test.Data | ||
{ | ||
public class TpcCustomer : TpcPerson | ||
{ | ||
public string Email { get; set; } | ||
public string Phone { get; set; } | ||
public DateTime AddedDate { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace N.EntityFrameworkCore.Extensions.Test.Data | ||
{ | ||
public abstract class TpcPerson | ||
{ | ||
[DatabaseGenerated(DatabaseGeneratedOption.None)] | ||
public long Id { get; set; } | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
| ||
namespace N.EntityFrameworkCore.Extensions.Test.Data | ||
{ | ||
public class TpcVendor : TpcPerson | ||
{ | ||
public string Email { get; set; } | ||
public string Phone { get; set; } | ||
public string Url { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace N.EntityFrameworkCore.Extensions.Test.Data | ||
{ | ||
public class TptCustomer : TptPerson | ||
{ | ||
public string Email { get; set; } | ||
public string Phone { get; set; } | ||
public DateTime AddedDate { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace N.EntityFrameworkCore.Extensions.Test.Data | ||
{ | ||
public class TptPerson | ||
{ | ||
[DatabaseGenerated(DatabaseGeneratedOption.None)] | ||
public long Id { get; set; } | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
| ||
namespace N.EntityFrameworkCore.Extensions.Test.Data | ||
{ | ||
public class TptVendor : TptPerson | ||
{ | ||
public string Email { get; set; } | ||
public string Phone { get; set; } | ||
public string Url { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.