相关疑难解决方法(0)

LINQ to Entities仅支持使用IEntity接口转换EDM原语或枚举类型

我有以下通用扩展方法:

public static T GetById<T>(this IQueryable<T> collection, Guid id) 
    where T : IEntity
{
    Expression<Func<T, bool>> predicate = e => e.Id == id;

    T entity;

    // Allow reporting more descriptive error messages.
    try
    {
        entity = collection.SingleOrDefault(predicate);
    }
    catch (Exception ex)
    {
        throw new InvalidOperationException(string.Format(
            "There was an error retrieving an {0} with id {1}. {2}",
            typeof(T).Name, id, ex.Message), ex);
    }

    if (entity == null)
    {
        throw new KeyNotFoundException(string.Format(
            "{0} with id {1} was not found.",
            typeof(T).Name, id));
    }

    return …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework expression-trees dbcontext

89
推荐指数
3
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

dbcontext ×1

entity-framework ×1

expression-trees ×1