All Projects → peschuster → PropertyTranslator

peschuster / PropertyTranslator

Licence: MS-PL license
Translates computed properties in LINQ queries into their implementation (based on Microsoft.Linq.Translations).

Programming Languages

C#
18002 projects
shell
77523 projects

Projects that are alternatives of or similar to PropertyTranslator

Nhibernate Core
NHibernate Object Relational Mapper
Stars: ✭ 1,918 (+13600%)
Mutual labels:  linq, linq-provider
sanity-linq
Strongly-typed .Net Client for Sanity
Stars: ✭ 36 (+157.14%)
Mutual labels:  linq, linq-provider
PocoDynamo
C# .NET Typed POCO Client for AWS Dynamo DB
Stars: ✭ 39 (+178.57%)
Mutual labels:  linq
DynamicQueryable
λ Construct Linq queries using strings.
Stars: ✭ 46 (+228.57%)
Mutual labels:  linq
ObservableComputations
Cross-platform .NET library for computations whose arguments and results are objects that implement INotifyPropertyChanged and INotifyCollectionChanged (ObservableCollection) interfaces.
Stars: ✭ 94 (+571.43%)
Mutual labels:  linq
OLGA
an Ontology SDK
Stars: ✭ 36 (+157.14%)
Mutual labels:  linq
multiplex.js
LINQ for JavaScript.
Stars: ✭ 79 (+464.29%)
Mutual labels:  linq
Morelinq
Extensions to LINQ to Objects
Stars: ✭ 2,833 (+20135.71%)
Mutual labels:  linq
linq
LINQ to Objects for Java.
Stars: ✭ 151 (+978.57%)
Mutual labels:  linq
Kendo.DynamicLinqCore
KendoNET.DynamicLinq implements server paging, filtering, sorting, grouping, and aggregating to Kendo UI via Dynamic Linq for .Net Core App(1.x ~ 3.x).
Stars: ✭ 36 (+157.14%)
Mutual labels:  linq
SoftUni-Software-Engineering
SoftUni- Software Engineering
Stars: ✭ 47 (+235.71%)
Mutual labels:  linq
Linq.Expression.Optimizer
System.Linq.Expression expressions optimizer. http://thorium.github.io/Linq.Expression.Optimizer
Stars: ✭ 81 (+478.57%)
Mutual labels:  linq
Linq.ts
linq for typescript
Stars: ✭ 33 (+135.71%)
Mutual labels:  linq
linq-fns
👴 LINQ for Javascript, written by TypeScript
Stars: ✭ 74 (+428.57%)
Mutual labels:  linq
Masuit.Tools
该仓库为 https://github.com/ldqk/Masuit.Tools 的镜像仓库,代码更新存在较大的延迟。建议前往源仓库:https://github.com/ldqk/Masuit.Tools
Stars: ✭ 755 (+5292.86%)
Mutual labels:  linq
QuickDAO
Simple Data Access Object library with LinQ and multiengine support for (Windows,Linux,OSX/IOS/Android) and freepascal (Windows/Linux)
Stars: ✭ 49 (+250%)
Mutual labels:  linq
Typescript.net
A JavaScript-Friendly .NET Based TypeScript Library (Moved)
Stars: ✭ 245 (+1650%)
Mutual labels:  linq
python-linq-samples
Python Linq Examples: Comparision of C# Linq functional programming to Python
Stars: ✭ 69 (+392.86%)
Mutual labels:  linq
linq2db.LINQPad
linq2db.LINQPad is a driver for LINQPad.
Stars: ✭ 65 (+364.29%)
Mutual labels:  linq
computation-expressions-workshop
F# Computation Expressions Workshop
Stars: ✭ 58 (+314.29%)
Mutual labels:  linq

PropertyTranslator

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 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());
        }
    }
}

How to use it

PropertyTranslator is on Nuget: http://nuget.org/packages/Linq.PropertyTranslator I'd recommend to use it together with QueryInterceptor by David Fowler.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].