Skip to content

SingleOrDefault or FirstOrDefault does not work #43

Open
@jeremy-morren

Description

@jeremy-morren

The Linq Function "DefaultIfEmpty" does not work with JetEntityFrameworkProvider. Upon investigation, the reason is that EntityFramework uses "LEFT OUTER JOIN" in the expression, which is not supported in Access.

For Example:

//Attempts to use "LEFT OUTER JOIN"
//Will throw Exception "Join Expression not supported"
Entity.Table.DefaultIfEmpty(null).FirstOrDefault(e => e.Id = 1)

As a caveat, this is a problem with Access, not JetEntityFrameworkProvider. The workaround I am using is the following extension method:

namespace System.Linq
{
    public static class LinqExtensions
    {
        /// 
        /// Workaround for 
        /// not working with JetEntity
        /// 
        /// First Value, otherwise default()
        public static TSource FirstOrEmpty(this IQueryable source, Expressions.Expression> predicate)
        {
            IQueryable result = source.Where(predicate);
            if (result.Count() == 0)
                return default(TSource);
            return result.First();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions