Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Table-Valued function support to EntityMapping. #147

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# top-most EditorConfig file
root = true

# Code files
[*]
indent_size = 4
indent_style = space
7 changes: 2 additions & 5 deletions Dapper.FastCrud.Benchmarks/Dapper.FastCrud.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Dapper.FastCrud.Benchmarks</RootNamespace>
<AssemblyName>Dapper.FastCrud.Benchmarks</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -87,10 +88,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper.FastCrud.Tests\Dapper.FastCrud.Tests.csproj">
<Project>{0fc75c39-9eb9-445c-ac0c-e1fbf79bbdf2}</Project>
<Name>Dapper.FastCrud.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Dapper.FastCrud\Dapper.FastCrud.csproj">
<Project>{a2b22949-0db7-4130-b813-420b839774b2}</Project>
<Name>Dapper.FastCrud</Name>
Expand Down
18 changes: 9 additions & 9 deletions Dapper.FastCrud.Benchmarks/app.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<!--For all the connection strings, the database will be added by the tests-->
Expand All @@ -12,22 +12,22 @@
</connectionStrings>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="NUnit" />
<unitTestProvider name="NUnit"/>
<stepAssemblies>
<stepAssembly assembly="Dapper.FastCrud.Tests" />
<stepAssembly assembly="Dapper.FastCrud.Tests"/>
</stepAssemblies>
</specFlow>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
</configuration>
2 changes: 1 addition & 1 deletion Dapper.FastCrud.Tests/CrudSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public void WhenIQueryForAMaximumOfWorkstationEntitiesInReverseOrderOfWorkstatio
public void WhenIPartiallyUpdateAllTheInsertedEmployeeEntities()
{
// prepare a new mapping
var defaultMapping = OrmConfiguration.GetDefaultEntityMapping<Employee>();
var defaultMapping = OrmConfiguration.GetDefaultEntityMapping<Employee>() as Mappings.EntityMapping<Employee>;
Assert.IsTrue(defaultMapping.IsFrozen);

var lastNamePropMapping = defaultMapping.GetProperty(employee => employee.LastName);
Expand Down
3 changes: 2 additions & 1 deletion Dapper.FastCrud.Tests/Dapper.FastCrud.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Dapper.FastCrud.Tests</RootNamespace>
<AssemblyName>Dapper.FastCrud.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
123 changes: 0 additions & 123 deletions Dapper.FastCrud.Tests/Models/ModelGeneratorConfig1.cs
Original file line number Diff line number Diff line change
@@ -1,124 +1 @@

// This file was automatically generated by the Dapper.FastCRUD T4 Template
// Do not make changes directly to this file - edit the template configuration instead
//
// The following connection settings were used to generate this file
//
// Connection String Name: `EntityGeneration`
// Provider: `System.Data.SqlClient`
// Connection String: `Data Source=(LocalDb)\MSSQLLocalDb;AttachDbFilename=D:\_Projects\Dapper.FastCRUD\Dapper.FastCRUD.Tests\App_Data\\EntityGenDatabase.mdf;Initial Catalog=EntityGenDatabase;Integrated Security=True`
// Include Views: `True`

namespace Dapper.FastCrud.Tests.Models
{
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Collections.Generic;

/// <summary>
/// Represents the CrazyColumns table.
/// </summary>
[Table("CrazyColumns")]
public partial class CrazyColumn
{
/// <summary>
/// Id Column
/// </summary>
[Key]
public virtual int Id { get; set; }
/// <summary>
/// Test starting with a digit
/// </summary>
[Column("123mb")]
public virtual int _123mb { get; set; }
/// <summary>
/// Test starting with a C# keyword
/// </summary>
[Column("switch")]
public virtual int @switch { get; set; }
}

/// <summary>
/// Represents the Employee table.
/// </summary>
[Table("Employee")]
public partial class Employee
{
/// <summary>
/// UserId Column
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int UserId { get; set; }
/// <summary>
/// EmployeeId Column
/// </summary>
[Key]
[Dapper.FastCrud.DatabaseGeneratedDefaultValue]
public virtual Guid EmployeeId { get; set; }
/// <summary>
/// KeyPass Column
/// </summary>
[Dapper.FastCrud.DatabaseGeneratedDefaultValue]
public virtual Guid KeyPass { get; set; }
/// <summary>
/// LastName Column
/// </summary>
public virtual string LastName { get; set; }
/// <summary>
/// FirstName Column
/// </summary>
public virtual string FirstName { get; set; }
/// <summary>
/// BirthDate Column
/// </summary>
public virtual DateTime BirthDate { get; set; }
/// <summary>
/// WorkstationId Column
/// </summary>
[ForeignKey("Workstation")]
public virtual long? WorkstationId { get; set; }
/// <summary>
/// FullName Column
/// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public virtual string FullName { get; set; }
public virtual Workstation Workstation { get; set; }
}

/// <summary>
/// Represents the Workstations table.
/// </summary>
[Table("Workstations")]
public partial class Workstation
{
/// <summary>
/// WorkstationId Column
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual long WorkstationId { get; set; }
/// <summary>
/// Name Column
/// </summary>
public virtual string Name { get; set; }
/// <summary>
/// AccessLevel Column
/// </summary>
[Dapper.FastCrud.DatabaseGeneratedDefaultValue]
public virtual int AccessLevel { get; set; }
/// <summary>
/// InventoryIndex Column
/// </summary>
public virtual int InventoryIndex { get; set; }
/// <summary>
/// 10PinSlots Column
/// </summary>
[Column("10PinSlots")]
public virtual int? _10PinSlots { get; set; }
public virtual IEnumerable<Employee> Employees { get; set; }
}

}

4 changes: 2 additions & 2 deletions Dapper.FastCrud.Tests/SqlBuilderSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public void ThenIShouldGetAValidJoinQueryStatementForWorkstation()
{
var buildingSqlBuilder = OrmConfiguration.GetSqlBuilder<Building>();
var expectedQuery =
$@" SELECT {_currentSqlBuilder.GetTableName()}.{_currentSqlBuilder.GetColumnName(nameof(Workstation.WorkstationId))}, {buildingSqlBuilder.GetTableName()}.{buildingSqlBuilder.GetColumnName(nameof(Building.BuildingId))}
$@" SELECT {_currentSqlBuilder.GetTableAliasName()}.{_currentSqlBuilder.GetColumnName(nameof(Workstation.WorkstationId))}, {buildingSqlBuilder.GetTableAliasName()}.{buildingSqlBuilder.GetColumnName(nameof(Building.BuildingId))}
FROM {_currentSqlBuilder.GetTableName()}, {buildingSqlBuilder.GetTableName()}
WHERE {_currentSqlBuilder.GetTableName()}.{_currentSqlBuilder.GetColumnName(nameof(Workstation.BuildingId))} = {buildingSqlBuilder.GetTableName()}.{buildingSqlBuilder.GetColumnName(nameof(Building.BuildingId))}";
WHERE {_currentSqlBuilder.GetTableAliasName()}.{_currentSqlBuilder.GetColumnName(nameof(Workstation.BuildingId))} = {buildingSqlBuilder.GetTableAliasName()}.{buildingSqlBuilder.GetColumnName(nameof(Building.BuildingId))}";

Assert.AreEqual(expectedQuery, _buildingRawJoinQueryStatement);
}
Expand Down
2 changes: 1 addition & 1 deletion Dapper.FastCrud.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
</specFlow>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<system.data>
<DbProviderFactories>
Expand Down
19 changes: 5 additions & 14 deletions Dapper.FastCrud.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{54E575C2-7D28-48E1-91FD-694DEEB09CD0}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -12,10 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper.FastCrud", "Dapper.FastCrud\Dapper.FastCrud.csproj", "{A2B22949-0DB7-4130-B813-420B839774B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.FastCrud.Tests", "Dapper.FastCrud.Tests\Dapper.FastCrud.Tests.csproj", "{0FC75C39-9EB9-445C-AC0C-E1FBF79BBDF2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.FastCrud.Benchmarks", "Dapper.FastCrud.Benchmarks\Dapper.FastCrud.Benchmarks.csproj", "{ED7BCE12-A776-437B-A1D1-9E3D3AE5A90B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper.FastCrud.ModelGenerator", "Dapper.FastCrud.ModelGenerator\Dapper.FastCrud.ModelGenerator.csproj", "{61E1B675-C862-4AB8-828E-AE2360DDD11C}"
EndProject
Global
Expand All @@ -28,14 +24,6 @@ Global
{A2B22949-0DB7-4130-B813-420B839774B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2B22949-0DB7-4130-B813-420B839774B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2B22949-0DB7-4130-B813-420B839774B2}.Release|Any CPU.Build.0 = Release|Any CPU
{0FC75C39-9EB9-445C-AC0C-E1FBF79BBDF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FC75C39-9EB9-445C-AC0C-E1FBF79BBDF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FC75C39-9EB9-445C-AC0C-E1FBF79BBDF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FC75C39-9EB9-445C-AC0C-E1FBF79BBDF2}.Release|Any CPU.Build.0 = Release|Any CPU
{ED7BCE12-A776-437B-A1D1-9E3D3AE5A90B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED7BCE12-A776-437B-A1D1-9E3D3AE5A90B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED7BCE12-A776-437B-A1D1-9E3D3AE5A90B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED7BCE12-A776-437B-A1D1-9E3D3AE5A90B}.Release|Any CPU.Build.0 = Release|Any CPU
{61E1B675-C862-4AB8-828E-AE2360DDD11C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61E1B675-C862-4AB8-828E-AE2360DDD11C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61E1B675-C862-4AB8-828E-AE2360DDD11C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -44,4 +32,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0E95A1DF-B9B5-4071-9F7E-DC1CE43EABD1}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
namespace Dapper.FastCrud.Configuration.DialectOptions
{
internal class MsSqlDatabaseOptions:SqlDatabaseOptions
internal class MsSqlDatabaseOptions : SqlDatabaseOptions
{
public MsSqlDatabaseOptions()
{
this.StartDelimiter = "[";
this.EndDelimiter = "]";
this.IsUsingSchemas = true;
this.DefaultSchema = "dbo";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public PostreSqlDatabaseOptions()
{
this.StartDelimiter = this.EndDelimiter = "\"";
this.IsUsingSchemas = true;
this.DefaultSchema = "public";
}
}
}
19 changes: 14 additions & 5 deletions Dapper.FastCrud/Configuration/OrmConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static void ClearEntityRegistrations()
/// Once the mappings have been used in query calls, the instance will be frozen and it won't support further modifications, but you can always call <see cref="EntityMapping{TEntity}.Clone"/> to create a new instance.
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
public static EntityMapping<TEntity> GetDefaultEntityMapping<TEntity>()
public static EntityMapping GetDefaultEntityMapping<TEntity>()
{
return GetEntityDescriptor<TEntity>().DefaultEntityMapping as EntityMapping<TEntity>;
return GetEntityDescriptor<TEntity>().DefaultEntityMapping;
}

/// <summary>
Expand All @@ -47,15 +47,24 @@ public static EntityMapping<TEntity> GetDefaultEntityMapping<TEntity>()
/// <typeparam name="TEntity">Entity type</typeparam>
public static EntityMapping<TEntity> RegisterEntity<TEntity>()
{
return SetDefaultEntityMapping(new EntityMapping<TEntity>());
return SetDefaultEntityMapping<TEntity>(new EntityMapping<TEntity>()) as EntityMapping<TEntity>;
}

/// <summary>
/// Registers a new entity. Please continue setting up property mappings and other entity options with the returned default entity mapping instance.
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
public static TableValuedFunctionEntityMapping<TEntity> RegisterTableValuedFunctionEntity<TEntity>()
{
return SetDefaultEntityMapping<TEntity>(new TableValuedFunctionEntityMapping<TEntity>()) as TableValuedFunctionEntityMapping<TEntity>;
}

/// <summary>
/// Sets the default entity type mapping for the entity type.
/// This must be called before any query operations were made on the entity.
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
public static EntityMapping<TEntity> SetDefaultEntityMapping<TEntity>(EntityMapping<TEntity> mappings)
public static EntityMapping SetDefaultEntityMapping<TEntity>(EntityMapping mappings)
{
Requires.NotNull(mappings, nameof(mappings));
Requires.Argument(!mappings.IsFrozen,nameof(mappings), "The entity mappings were frozen and can't be used as defaults. They must be cloned first.");
Expand All @@ -70,7 +79,7 @@ public static EntityMapping<TEntity> SetDefaultEntityMapping<TEntity>(EntityMapp
/// <typeparam name="TEntity">Entity type</typeparam>
/// <param name="entityMapping">If NULL, de default entity mapping will be used.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ISqlBuilder GetSqlBuilder<TEntity>(EntityMapping<TEntity> entityMapping = null)
public static ISqlBuilder GetSqlBuilder<TEntity>(EntityMapping entityMapping = null)
{
return GetEntityDescriptor<TEntity>().GetSqlStatements(entityMapping).SqlBuilder;
}
Expand Down
5 changes: 5 additions & 0 deletions Dapper.FastCrud/Configuration/SqlDatabaseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public SqlDatabaseOptions()
/// </summary>
public bool IsUsingSchemas { get; protected set; }

/// <summary>
/// Gets the default schema name.
/// </summary>
public string DefaultSchema { get; protected set; }

/// <summary>
/// Gets the prefix used for named parameters
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal abstract class AggregatedRelationalSqlStatementOptionsBuilder<TReferred
/// <summary>
/// Overrides the entity mapping for the current statement.
/// </summary>
public TStatementOptionsBuilder WithEntityMappingOverride(EntityMapping<TReferredEntity> entityMapping)
public TStatementOptionsBuilder WithEntityMappingOverride(EntityMapping entityMapping)
{
this.EntityMappingOverride = entityMapping;
return this.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public TStatementOptionsBuilder AttachToTransaction(IDbTransaction transaction)
/// <summary>
/// Overrides the entity mapping for the current statement.
/// </summary>
public TStatementOptionsBuilder WithEntityMappingOverride(EntityMapping<TEntity> entityMapping)
public TStatementOptionsBuilder WithEntityMappingOverride(EntityMapping entityMapping)
{
this.EntityMappingOverride = entityMapping;
return this.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ISqlRelationOptionsSetter<TReferredEntity, TStatementOptionsBui
/// <summary>
/// Overrides the entity mapping for the current statement.
/// </summary>
TStatementOptionsBuilder WithEntityMappingOverride(EntityMapping<TReferredEntity> entityMapping);
TStatementOptionsBuilder WithEntityMappingOverride(EntityMapping entityMapping);

/// <summary>
/// Limits the result set with a where clause.
Expand Down
Loading