-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#60 added the ability to map an entity to a view or query
- Loading branch information
1 parent
88a8457
commit e1f6ecd
Showing
21 changed files
with
436 additions
and
24 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
SubSonic.Core.DataAccessLayer/src/CodeGenerator/Models/Relationships.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,51 @@ | ||
using SubSonic.Attributes; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using System.Text; | ||
|
||
namespace SubSonic.CodeGenerator.Models | ||
{ | ||
[DbView(Query = SQL)] | ||
public class Relationship | ||
{ | ||
public const string SQL = | ||
@"SELECT | ||
TableName = FK.TABLE_NAME, | ||
ColumnName = CU.COLUMN_NAME, | ||
ForiegnTableName = PK.TABLE_NAME, | ||
ForiegnColumnName = PT.COLUMN_NAME, | ||
ConstraintName = C.CONSTRAINT_NAME, | ||
SchemaOwner = FK.TABLE_SCHEMA | ||
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C | ||
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME | ||
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME | ||
INNER JOIN | ||
( | ||
SELECT i1.TABLE_NAME, i2.COLUMN_NAME | ||
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1 | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME | ||
WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY' | ||
) | ||
PT ON PT.TABLE_NAME = PK.TABLE_NAME"; | ||
|
||
public string TableName { get; set; } | ||
|
||
public string ColumnName { get; set; } | ||
|
||
public string ForiegnTableName { get; set; } | ||
|
||
public string ForiegnColumnName { get; set; } | ||
|
||
public string ConstraintName { get; set; } | ||
|
||
public string SchemaOwner { get; set; } | ||
|
||
[ForeignKey(nameof(TableName))] | ||
public virtual Table Table { get; set; } | ||
|
||
[ForeignKey(nameof(ForiegnTableName))] | ||
public virtual Table ForiegnTable { 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
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
42 changes: 42 additions & 0 deletions
42
SubSonic.Core.DataAccessLayer/src/Linq/Expressions/DbViewExpression.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,42 @@ | ||
using SubSonic.Attributes; | ||
using SubSonic.Linq.Expressions; | ||
using SubSonic.Linq.Expressions.Alias; | ||
using SubSonic.Schema; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace SubSonic.Linq.Expressions | ||
{ | ||
public class DbViewExpression | ||
: DbTableExpression | ||
{ | ||
protected internal DbViewExpression(IDbEntityModel model, TableAlias alias) | ||
: base(model, alias) | ||
{ | ||
} | ||
|
||
public bool IsQuery => Query.IsNotNullOrEmpty(); | ||
|
||
public string Query | ||
{ | ||
get | ||
{ | ||
if (Model.EntityModelType.GetCustomAttribute<DbViewAttribute>() is DbViewAttribute dbView) | ||
{ | ||
return dbView.Query; | ||
} | ||
return default; | ||
} | ||
} | ||
} | ||
|
||
public partial class DbExpression | ||
{ | ||
public static DbExpression DbView(IDbEntityModel model, TableAlias alias) | ||
{ | ||
return new DbViewExpression(model, alias); | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
SubSonic.Core.DataAccessLayer/src/Logging/DebugLogProvider.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,22 @@ | ||
using SubSonic.Core.Logging; | ||
using SubSonic.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace SubSonic.Logging | ||
{ | ||
public class DebugLogProvider<TClassName> | ||
: LogProvider<TClassName, DebugLogger> | ||
{ | ||
public DebugLogProvider() | ||
: base() { } | ||
} | ||
|
||
public class TraceLogProvider<TClassName> | ||
: LogProvider<TClassName, TraceLogger> | ||
{ | ||
public TraceLogProvider() | ||
: base() { } | ||
} | ||
} |
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,26 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace SubSonic.Logging | ||
{ | ||
public class DebugLogger | ||
: Logger | ||
{ | ||
public DebugLogger() | ||
: base(LogLevel.Debug) { } | ||
|
||
public override void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | ||
{ | ||
if (formatter is null) | ||
{ | ||
throw new ArgumentNullException(nameof(formatter)); | ||
} | ||
|
||
if (IsEnabled(logLevel)) | ||
{ | ||
Debug.WriteLine(formatter(state, exception)); | ||
} | ||
} | ||
} | ||
} |
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,57 @@ | ||
using Microsoft.Extensions.Logging; | ||
using SubSonic.Core.Logging; | ||
using SubSonic.Logging; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace SubSonic.Logging | ||
{ | ||
public class LogProvider<TClassName, TLogger> | ||
: ILoggerProvider | ||
where TLogger : Logger, new() | ||
{ | ||
private readonly ConcurrentDictionary<string, ILogger> m_loggers; | ||
private bool disposedValue; | ||
|
||
protected LogProvider() | ||
{ | ||
this.m_loggers = new ConcurrentDictionary<string, ILogger>(); | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
return m_loggers.GetOrAdd($"{typeof(TClassName).Name}::{categoryName}", new TLogger()); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
m_loggers.Clear(); | ||
} | ||
|
||
// TODO: free unmanaged resources (unmanaged objects) and override finalizer | ||
// TODO: set large fields to null | ||
disposedValue = true; | ||
} | ||
} | ||
|
||
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources | ||
// ~LogProvider() | ||
// { | ||
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
// Dispose(disposing: false); | ||
// } | ||
|
||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.