Search for existing suggestions

Support C# 6 Expression-bodied function members in Linq-to-entities

C# 6 added the feature to define class attributes in Lambda like syntax as "Expression-bodied functions" - it would be great if EF could take advantage of these when parsing the expression tree for a Linq-to-entities query.

That way these attributes could be used in Linq-to-entities where statements and evaluated at the database level assuming they only used canonical functions.

So:

public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public string DisplayName => Title + " " + Content;

}

var query = from p in db.Posts
select p.DisplayName;
query.ToList();

Would end up as this SQL:

SELECT Title + ' ' + Content as DisplayName FROM dbo.Posts

Currently the only way to achieve this type of functionality is with a 3rd party library like https://github.com/damieng/Linq.Translations

(See also this answer on stack: http://stackoverflow.com/a/27383641/470183)

1 vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)

We’ll send you updates on this idea

James Close shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base