EntityFramework.Extended在EF6派生类型

时间:2015-12-31 11:33:15

标签: entity-framework-6 entityframework.extended

考虑以下EF实体:

public class Location
{
    [Key]
    public int LocationId { get; set; }

    [StringLength(50)]
    [Required]
    public string LocationDescription { get; set; }
}

public class LocationHolding : Location
{
    [StringLength(50)]
    [Required]
    public string LocationDescriptionHolding { get; set; }
}

上下文源自DbContext,并且只有一个DbSet

public IDbSet<Location> Location { get; set; }

尝试批量更新时使用EntityFramework.Extended包:

context.Location
    .OfType<LocationHolding>()
    .Where(x => true)
    .Update(u => new LocationHolding
    {
        LocationDescription = u.LocationDescriptionHolding
    });

抛出以下异常:

There are no EntitySets defined for the specified entity type 'TestEfHierarchy.Model.LocationHolding'.
If 'TestEfHierarchy.Model.LocationHolding' is a derived type, use the base type instead.
Parameter name: TEntity

虽然在针对简单单个实体的包中取得了成功,但我一直无法找到在更复杂的情况下使用它的示例。

对于实体层次结构,已尝试了每个层次的表和每个类型的表,两者都具有相同的结果。我发现工作的唯一情况是使用静态值进行更新(即LocationDescription =“Foo”),层次结构为TPH。

是否有人有类似的经历或找到其他替代方法?感谢存储过程等替代方法可用,但希望使用基于代码/流畅的方法。

0 个答案:

没有答案
相关问题