Linq.PropertyTranslator.Core
1.0.5.1
dotnet add package Linq.PropertyTranslator.Core --version 1.0.5.1
NuGet\Install-Package Linq.PropertyTranslator.Core -Version 1.0.5.1
<PackageReference Include="Linq.PropertyTranslator.Core" Version="1.0.5.1" />
<PackageVersion Include="Linq.PropertyTranslator.Core" Version="1.0.5.1" />
<PackageReference Include="Linq.PropertyTranslator.Core" />
paket add Linq.PropertyTranslator.Core --version 1.0.5.1
#r "nuget: Linq.PropertyTranslator.Core, 1.0.5.1"
#addin nuget:?package=Linq.PropertyTranslator.Core&version=1.0.5.1
#tool nuget:?package=Linq.PropertyTranslator.Core&version=1.0.5.1
Linq.PropertyTranslator.Core
This is a .NET Core / .NET Standard port of the PropertyTranslator (https://github.com/peschuster/PropertyTranslator).
The following frameworks are supported:
- net40
- net45
- net45x
- net46
- netstandard1.3
- netstandard2.0
Translates computed properties in LINQ queries into their implementation (based on Microsoft.Linq.Translations).
What does it?
PropertyTranslator exchanges properties in linq queries before execution. This is especially useful if the underlying LINQ provider does not support some kind of operation or you want to add client-side calculations in your business logic to e.g. an EntityFramework model.
For a general introduction into the topic, have a look at this blog post. PropertyTranslator actually is a enhancement of the presented solution in the post.
For an introduction specifically to PropertyTranslator have a look at these two blog posts: LINQ: How to dynamically map properties and PropertyTranslator and Interfaces
What's the difference to Linq.Translations?
PropertyTranslator plays well together with QueryInterceptor.Core and thus can be added to every query in some kind of "data context" or general table / ObjectSet provider.
Furthermore it internally adds one more layer of abstraction to allow property translation depending on the ui culture of the current thread.
Examples
Basic example
A POCO entity class from EntityFramework. Although in the database only a FirstName
and a LastName
field exists, the property Name
can be used in queries, because right before execution of the query it is translated to FirstName + ' ' + LastName
.
public class Person
{
private static readonly CompiledExpressionMap<Person, string> fullNameExpression =
DefaultTranslationOf<Person>.Property(p => p.FullName).Is(p => p.FirstName + " " + p.LastName);
public string FullName
{
get { return fullNameExpression.Evaluate(this); }
}
public string FirstName { get; set; }
public string LastName { get; set; }
}
A more advanced example with ui culture dependent translations
The context: a database table, mapped with entity framework to POCO entity classes with two fields: EnglishName
and GermanName
. With the following snippet, you can use the Name
property in linq queries which resolves to the name (either EnglishName
or GermanName
) depending on the current ui culture.
public class Country
{
private static readonly CompiledExpressionMap<Country, string> nameExpression =
DefaultTranslationOf<Country>.Property(c => c.Name).Is(c => c.EnglishName);
static Country()
{
DefaultTranslationOf<Country>.Property(c => c.Name).Is(c => c.EnglishName, 'en');
DefaultTranslationOf<Country>.Property(c => c.Name).Is(c => c.GermanName, 'de');
}
public string Name
{
get { return nameExpression.Evaluate(this); }
}
public string EnglishName { get; set; }
public string GermanName { get; set; }
}
How to enable PropertyTranslator
You can enable PropertyTranslator by adding the PropertyVisitor
to your EntityFramework ObjectSets (of course it works not only with EntityFramework but with any LINQ provider):
using QueryInterceptor;
using PropertyTranslator;
public class MyDataContext
{
ObjectContext context = new MyEfContext();
public IQueryable<Person> PersonTable
{
get
{
var objectSet = context.CreateObjectSet<Person>("Persons");
return objectSet.InterceptWith(new PropertyVisitor());
}
}
}
Sponsors
Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of Linq.PropertyTranslator.Core.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 is compatible. net452 is compatible. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.5.1
- No dependencies.
-
.NETFramework 4.5.2
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- System.Diagnostics.Debug (>= 4.3.0)
- System.Globalization (>= 4.3.0)
- System.Linq.Queryable (>= 4.3.0)
- System.Reflection.TypeExtensions (>= 4.3.0)
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Linq.PropertyTranslator.Core:
Repository | Stars |
---|---|
zzzprojects/System.Linq.Dynamic.Core
The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
|
See CHANGELOG.MD