Skip to content

Commit 1503656

Browse files
committed
4.2.0-beta.1 check in
1 parent 30640e2 commit 1503656

12 files changed

+1124
-0
lines changed

LICENSE LICENSE.MD

File renamed without changes.

SubSonic.Extensions.SqlServer.csproj

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<IsPackable>true</IsPackable>
6+
<Platforms>AnyCPU</Platforms>
7+
<Authors>Kenneth Carter</Authors>
8+
<Description>Sql Client Wrapper for the SubSonic Data Layer</Description>
9+
<Copyright>Kenneth Carter © 2020</Copyright>
10+
<IncludeSymbols>true</IncludeSymbols>
11+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
12+
<RepositoryType>Git</RepositoryType>
13+
<PackageTags>DAL; SqlClient;</PackageTags>
14+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
15+
<PackageLicenseFile>LICENSE.MD</PackageLicenseFile>
16+
<PackageProjectUrl>https://github.com/SubSonic-Core/SubSonic.Core/projects/</PackageProjectUrl>
17+
<RepositoryUrl>https://github.com/SubSonic-Core/SubSonic.Core.Extensions.SqlServer</RepositoryUrl>
18+
<Version>4.2.0-beta.1</Version>
19+
<NeutralLanguage>en</NeutralLanguage>
20+
<SignAssembly>true</SignAssembly>
21+
<DelaySign>false</DelaySign>
22+
<AssemblyOriginatorKeyFile>SubSonicStrongName.snk</AssemblyOriginatorKeyFile>
23+
</PropertyGroup>
24+
25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DefineConstants>TRACE;DEBUG</DefineConstants>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0" />
32+
<PackageReference Include="SubSonic.Core.DAL" Version="4.1.1" />
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<None Include="LICENSE.MD">
37+
<Pack>True</Pack>
38+
<PackagePath></PackagePath>
39+
</None>
40+
</ItemGroup>
41+
42+
</Project>

SubSonic.Extensions.SqlServer.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30225.117
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubSonic.Extensions.SqlServer", "SubSonic.Extensions.SqlServer.csproj", "{F9539387-24E5-41F9-96C0-963EE1F48D9E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F9539387-24E5-41F9-96C0-963EE1F48D9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F9539387-24E5-41F9-96C0-963EE1F48D9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F9539387-24E5-41F9-96C0-963EE1F48D9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F9539387-24E5-41F9-96C0-963EE1F48D9E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {67EBF82A-65CF-47DB-A38A-631A2F996C97}
24+
EndGlobalSection
25+
EndGlobal

SubSonicStrongName.snk

596 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using SubSonic;
2+
using System.Data;
3+
4+
namespace SubSonic.Extensions.SqlServer
5+
{
6+
public class DbSqlParameterAttribute
7+
: DbParameterAttribute
8+
{
9+
public DbSqlParameterAttribute(string name)
10+
: base(name)
11+
{
12+
}
13+
14+
private SqlDbType sqlDbType;
15+
16+
public SqlDbType SqlDbType
17+
{
18+
get
19+
{
20+
return sqlDbType;
21+
}
22+
set
23+
{
24+
sqlDbType = value;
25+
26+
DbType = TypeConvertor.ToDbType(value);
27+
}
28+
}
29+
}
30+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using SubSonic;
2+
using SubSonic.Schema;
3+
using System.Data;
4+
5+
namespace SubSonic.Extensions.SqlServer
6+
{
7+
public class SubSonicSqlParameter
8+
: SubSonicParameter
9+
{
10+
public SubSonicSqlParameter(string name, object value)
11+
: base(name, value)
12+
{
13+
SqlDbType = TypeConvertor.ToSqlDbType(value.GetType(), SubSonicContext.DbOptions.SupportUnicode);
14+
}
15+
16+
public SubSonicSqlParameter(string name, object value, IDbEntityProperty property)
17+
: base(name, value, property)
18+
{
19+
SqlDbType = TypeConvertor.ToSqlDbType(property.DbType, SubSonicContext.DbOptions.SupportUnicode);
20+
}
21+
22+
private SqlDbType sqlDbType;
23+
24+
public SqlDbType SqlDbType
25+
{
26+
get
27+
{
28+
return sqlDbType;
29+
}
30+
set
31+
{
32+
sqlDbType = value;
33+
34+
DbType = TypeConvertor.ToDbType(value, SubSonicContext.DbOptions.SupportUnicode);
35+
}
36+
}
37+
}
38+
}

src/Data/Linq/Binary.cs

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Runtime.Serialization;
5+
using System.Text;
6+
7+
namespace SubSonic.Data.Linq
8+
{
9+
[SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces", Justification = "Microsoft: The name clearly describes function and the namespace is under a DLinq namespace which will make the distinction clear.")]
10+
[DataContract]
11+
[Serializable]
12+
public sealed class Binary : IEquatable<Binary>
13+
{
14+
[DataMember(Name = "Bytes")]
15+
readonly byte[] bytes;
16+
int? hashCode;
17+
18+
public Binary(byte[] value)
19+
{
20+
if (value == null)
21+
{
22+
this.bytes = new byte[0];
23+
}
24+
else
25+
{
26+
this.bytes = new byte[value.Length];
27+
Array.Copy(value, this.bytes, value.Length);
28+
}
29+
this.ComputeHash();
30+
}
31+
32+
public byte[] ToArray()
33+
{
34+
byte[] copy = new byte[this.bytes.Length];
35+
Array.Copy(this.bytes, copy, copy.Length);
36+
return copy;
37+
}
38+
39+
public int Length
40+
{
41+
get { return this.bytes.Length; }
42+
}
43+
44+
public static implicit operator Binary(byte[] value)
45+
{
46+
return new Binary(value);
47+
}
48+
49+
public bool Equals(Binary other)
50+
{
51+
return this.EqualsTo(other);
52+
}
53+
54+
public static bool operator ==(Binary binary1, Binary binary2)
55+
{
56+
if ((object)binary1 == (object)binary2)
57+
return true;
58+
if (binary1 is null && binary2 is null)
59+
return true;
60+
if (binary1 is null || binary2 is null)
61+
return false;
62+
return binary1.EqualsTo(binary2);
63+
}
64+
65+
public static bool operator !=(Binary binary1, Binary binary2)
66+
{
67+
if (binary1 == (object)binary2)
68+
return false;
69+
if (binary1 is null && binary2 is null)
70+
return false;
71+
if (binary1 is null || binary2 is null)
72+
return true;
73+
return !binary1.EqualsTo(binary2);
74+
}
75+
76+
public override bool Equals(object obj)
77+
{
78+
return EqualsTo(obj as Binary);
79+
}
80+
81+
public override int GetHashCode()
82+
{
83+
if (!hashCode.HasValue)
84+
{
85+
// hash code is not marked [DataMember], so when
86+
// using the DataContractSerializer, we'll need
87+
// to recompute the hash after deserialization.
88+
ComputeHash();
89+
}
90+
return this.hashCode.Value;
91+
}
92+
93+
public override string ToString()
94+
{
95+
StringBuilder sb = new StringBuilder();
96+
sb.Append("\"");
97+
sb.Append(Convert.ToBase64String(bytes, 0, bytes.Length));
98+
sb.Append("\"");
99+
return sb.ToString();
100+
}
101+
102+
private bool EqualsTo(Binary binary)
103+
{
104+
if ((this) == (object)binary)
105+
return true;
106+
if (binary is null)
107+
return false;
108+
if (bytes.Length != binary.bytes.Length)
109+
return false;
110+
if (GetHashCode() != binary.GetHashCode())
111+
return false;
112+
for (int i = 0, n = bytes.Length; i < n; i++)
113+
{
114+
if (bytes[i] != binary.bytes[i])
115+
return false;
116+
}
117+
return true;
118+
}
119+
120+
/// <summary>
121+
/// Simple hash using pseudo-random coefficients for each byte in
122+
/// the array to achieve order dependency.
123+
/// </summary>
124+
private void ComputeHash()
125+
{
126+
int s = 314, t = 159;
127+
hashCode = 0;
128+
for (int i = 0; i < bytes.Length; i++)
129+
{
130+
hashCode = hashCode * s + bytes[i];
131+
s *= t;
132+
}
133+
}
134+
}
135+
}

src/Data/SubSonicSqlClient.cs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Data;
3+
using System.Data.Common;
4+
using Microsoft.Data.SqlClient;
5+
6+
namespace SubSonic.Extensions.SqlServer
7+
{
8+
using Factory;
9+
using Schema;
10+
11+
12+
public class SubSonicSqlClient
13+
: SubSonicDbProvider<SqlClientFactory>
14+
{
15+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "Provider Factory Pattern")]
16+
public static readonly SubSonicSqlClient Instance = new SubSonicSqlClient();
17+
18+
protected SubSonicSqlClient()
19+
: base(SqlClientFactory.Instance)
20+
{
21+
QueryProvider = new SqlServerQueryProvider();
22+
}
23+
24+
public override ISqlQueryProvider QueryProvider { get; }
25+
26+
public override DbDataAdapter CreateDataAdapter(DbCommand select)
27+
{
28+
DbDataAdapter adapter = CreateDataAdapter();
29+
30+
adapter.SelectCommand = select;
31+
32+
return adapter;
33+
}
34+
35+
public override DbParameter CreateParameter(SubSonicParameter parameter)
36+
{
37+
SqlParameter db = (SqlParameter)CreateParameter();
38+
39+
db.Map(parameter);
40+
41+
return db;
42+
}
43+
44+
public override DbParameter CreateParameter(string name, object value, IDbEntityProperty property)
45+
{
46+
if (property is null)
47+
{
48+
return new SubSonicSqlParameter(name, value);
49+
}
50+
else
51+
{
52+
return new SubSonicSqlParameter(name, value, property);
53+
}
54+
}
55+
56+
public override DbParameter CreateParameter(string name, object value)
57+
{
58+
return CreateParameter(name, value, null);
59+
}
60+
61+
public override DbParameter CreateParameter(string name, object value, bool mandatory, int size, bool isUserDefinedTableParameter, string udtType, ParameterDirection direction)
62+
{
63+
var sqlParameter = new SqlParameter("@" + name, value ?? DBNull.Value)
64+
{
65+
Direction = direction,
66+
IsNullable = !mandatory,
67+
Size = size,
68+
};
69+
70+
if (isUserDefinedTableParameter)
71+
{
72+
sqlParameter.TypeName = udtType;
73+
}
74+
//else
75+
//{
76+
// sqlParameter.SqlDbType = (SqlDbType)dbType;
77+
//}
78+
79+
return sqlParameter;
80+
}
81+
82+
83+
}
84+
}

src/Extensions/SqlClientExtensions.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Data.Common;
3+
4+
namespace SubSonic.Extensions.SqlServer
5+
{
6+
7+
8+
public static partial class SqlServerExtensions
9+
{
10+
public static DbContextOptionsBuilder UseSqlClient(this DbContextOptionsBuilder builder, Action<DbConnectionStringBuilder, SubSonicContextOptions> config = null)
11+
{
12+
if (builder is null)
13+
{
14+
throw new ArgumentNullException(nameof(builder));
15+
}
16+
17+
Type providerFactoryType = typeof(SubSonicSqlClient);
18+
19+
string providerInvariantName = providerFactoryType.Namespace;
20+
21+
builder
22+
.RegisterProviderFactory(providerInvariantName, providerFactoryType)
23+
.SetDefaultProvider(providerInvariantName)
24+
.SetConnectionStringBuilder(config);
25+
26+
return builder;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)