Skip to content

Commit

Permalink
Merge pull request #53 from linq2db/master
Browse files Browse the repository at this point in the history
Release 3.3.0
  • Loading branch information
sdanyliv authored Jun 19, 2020
2 parents 47c18f9 + f9c108f commit b2497fd
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Build/linq2db.Default.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.2.0</Version>
<Version>3.3.0</Version>

<Description>Allows to execute Linq to DB (linq2db) queries in Entity Framework Core DbContext.</Description>
<Title>Linq to DB (linq2db) extensions for Entity Framework Core</Title>
Expand Down
2 changes: 1 addition & 1 deletion NuGet/linq2db.EntityFrameworkCore.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.3" />
<dependency id="linq2db" version="3.0.0-rc.0" />
<dependency id="linq2db" version="3.0.0-rc.1" />
</group>
</dependencies>
</metadata>
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
* NuGet [![NuGet](https://img.shields.io/nuget/vpre/linq2db.EntityFrameworkCore.svg)](https://www.nuget.org/packages/linq2db.EntityFrameworkCore)
* Azure Artifacts [![MyGet](https://img.shields.io/badge/azure-download-yellowgreen)](https://dev.azure.com/linq2db/linq2db/_packaging?_a=package&feed=linq2db&view=versions&package=linq2db.EntityFrameworkCore&protocolType=NuGet) ([feed]( https://pkgs.dev.azure.com/linq2db/linq2db/_packaging/linq2db/nuget/v3/index.json))

# Unique features
* Fast Eager Loading (incomparable faster on massive `Include` query)
* Global Query Filters optimization
* Better SQL optimization
* [Use CTE in LINQ queries](https://linq2db.github.io/articles/sql/CTE.html)
* [MERGE statement support](https://linq2db.github.io/articles/sql/merge/Merge-API-Description.html)
* Table hints
* [Full Window functions support](https://linq2db.github.io/articles/sql/Window-Functions-(Analytic-Functions).html)
* Fast [BulkCopy](https://linq2db.github.io/articles/sql/Bulk-Copy.html) of millions records
* Native SQL operations for updating, deleting, inserting records via LINQ query
* Temporary Tables support
* Cross Database/Linked Server queries.
* Full Text Search extensions
* A lot of extensions to cover ANSI SQL
# How to use

In your code you need to initialize integration using following call:
Expand Down Expand Up @@ -141,10 +155,9 @@ Below is a list of providers, that should work right now:
- SQL Server CE

# Know limitations
- No Eager loading
- No Lazy loading
- No way to work with in-memory database
- `Include` function supported with limitations
- `HasConversion` for properties currently not supported. Can be done via linq2db's `MappingSchema.Default.SetConverter()` function.

# Help! It doesn't work!

Expand Down
49 changes: 45 additions & 4 deletions Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ static bool CompareProperty(MemberInfo property, MemberInfo memberInfo)
{
if (property == memberInfo)
return true;

if (property == null)
return false;

if (memberInfo.DeclaringType?.IsAssignableFrom(property.DeclaringType) == true
&& memberInfo.Name == property.Name
Expand Down Expand Up @@ -214,9 +217,8 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru

return associations.Select(a => (T)(Attribute)a).ToArray();
}
}

if (typeof(T) == typeof(Sql.ExpressionAttribute))
}
else if (typeof(T) == typeof(Sql.ExpressionAttribute))
{
// Search for translator first
if (_dependencies != null)
Expand Down Expand Up @@ -260,10 +262,47 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
}).ToArray();
}
}
else if (typeof(T) == typeof(ValueConverterAttribute))
{
var et = _model?.FindEntityType(type);
if (et != null)
{
var props = et.GetProperties();
var prop = props.FirstOrDefault(p => CompareProperty(p, memberInfo));

var converter = prop?.GetValueConverter();
if (converter != null)
{
var valueConverterAttribute = new ValueConverterAttribute
{
ValueConverter = new ValueConverter(converter.ConvertToProviderExpression,
converter.ConvertFromProviderExpression, false)
};
return new T[] { (T) (Attribute) valueConverterAttribute };
}
}
}

return Array.Empty<T>();
}

class ValueConverter : IValueConverter
{
public ValueConverter(
LambdaExpression convertToProviderExpression,
LambdaExpression convertFromProviderExpression, bool handlesNulls)
{
FromProviderExpression = convertFromProviderExpression;
ToProviderExpression = convertToProviderExpression;
HandlesNulls = handlesNulls;
}

public bool HandlesNulls { get; }
public LambdaExpression FromProviderExpression { get; }
public LambdaExpression ToProviderExpression { get; }

}

class SqlTransparentExpression : SqlExpression
{
public Expression Expression { get; }
Expand Down Expand Up @@ -329,7 +368,9 @@ private Sql.ExpressionAttribute GetDbFunctionFromProperty(Type type, PropertyInf
{
EFCoreExpressionAttribute result = null;

if ((propInfo.GetMethod?.IsStatic != true) && !mi.GetCustomAttributes<Sql.ExpressionAttribute>().Any())
if ((propInfo.GetMethod?.IsStatic != true)
&& !(mi is DynamicColumnInfo)
&& !mi.GetCustomAttributes<Sql.ExpressionAttribute>().Any())
{
var objExpr = new SqlTransparentExpression(Expression.Constant(DefaultValue.GetValue(type), type), _mappingSource?.FindMapping(propInfo));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="linq2db" Version="3.0.0-rc.0" />
<PackageReference Include="linq2db" Version="3.0.0-rc.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public void TestJsonConvert()
{
LinqToDBForEFTools.Initialize();

// converting from string, because usually JSON is stored as string, but it depends on DataProvider
Mapping.MappingSchema.Default.SetConverter<string, LocalizedString>(v => JsonConvert.DeserializeObject<LocalizedString>(v));

// here we told linq2db how to pass converted value as DataParameter.
Mapping.MappingSchema.Default.SetConverter<LocalizedString, DataParameter>(v => new DataParameter("", JsonConvert.SerializeObject(v), LinqToDB.DataType.NVarChar));
// // converting from string, because usually JSON is stored as string, but it depends on DataProvider
// Mapping.MappingSchema.Default.SetConverter<string, LocalizedString>(v => JsonConvert.DeserializeObject<LocalizedString>(v));
//
// // here we told linq2db how to pass converted value as DataParameter.
// Mapping.MappingSchema.Default.SetConverter<LocalizedString, DataParameter>(v => new DataParameter("", JsonConvert.SerializeObject(v), LinqToDB.DataType.NVarChar));

using (var ctx = new JsonConvertContext(_options))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void ConfigureGlobalQueryFilters(ModelBuilder builder)
if (typeof(ISoftDelete).IsSameOrParentOf(entityType.ClrType))
{
var method = ConfigureEntityFilterMethodInfo.MakeGenericMethod(entityType.ClrType);
method.Invoke(this, new object?[] { builder });
method.Invoke(this, new object[] { builder });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void SetIdentityInsert(DbContext ctx, string tableName, bool isOn)
var str = $"SET IDENTITY_INSERT {tableName} " + (isOn ? "ON" : "OFF");
try
{
ctx.Database.ExecuteSqlCommand(str);
ctx.Database.ExecuteSqlRaw(str);
}
catch (Exception)
{
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
variables:
solution: 'linq2db.EFCore.sln'
build_configuration: 'Release'
assemblyVersion: 3.2.0
nugetVersion: 3.2.0
assemblyVersion: 3.3.0
nugetVersion: 3.3.0
artifact_nugets: 'nugets'

# build on commits to important branches (master + release branches):
Expand Down

0 comments on commit b2497fd

Please sign in to comment.