1

考虑以下 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。

有没有人有类似的经历或找到替代的解决方法?赞赏可以使用存储过程等替代方法,但希望使用基于代码/流畅的方法。

4

0 回答 0