无法确定复合主键排序

时间:2016-03-09 12:04:59

标签: c# entity-framework-6

我有给定的EF实体。

    [Key]
    [Column("ACTIVITY.ID", Order = 0)]
    public string ActivityId { get; set; }

    [Key]
    [Column("STATISTIC.SECTION", Order = 1)]
    public string StatisticSection { get; set; }

    [Key]
    [Column("STATISTIC.NAME", Order = 2)]
    public string StatisticName { get; set; }

    [Key]
    [Column("LAP.ID", Order = 3)]
    public string LapId { get; set; }

    [Column("STATISTIC.TYPE")]
    public string StatisticType { get; set; }

    [Column("STATISTIC.VALUE")]
    public string StatisticValue { get; set; }

    [Column("STATISTIC.UNIT")]
    public string StatisticUnit { get; set; }

当使用下面的方法进行插入操作时:

    public bool Add(ICollection<RefLapStatistic> entities)
    {
        return HandleInsert(() =>
        {
            using (var context = new ReportingRefDataContext(DataSource))
            {
                var activities = entities.Select(x => x.ActivityId).Distinct();
                var entitiesToDelete = context.LapStatistics
                .Where(x => activities.Any(y => x.ActivityId.Equals(y, System.StringComparison.OrdinalIgnoreCase)));

                context.LapStatistics.RemoveRange(entitiesToDelete);

                entities.ToList().ForEach(x => context.LapStatistics.Add(Mapper.Map< RefLapStatisticEntity>(x)));

                return context.SaveChanges() > 0;
            }
        });
    }

执行下面的行时出现以下错误:

var entitiesToDelete = context.LapStatistics
                .Where(x => activities.Any(y => x.ActivityId.Equals(y, System.StringComparison.OrdinalIgnoreCase)));
  

无法确定类型

的复合主键排序

我不知道为什么会发生这种情况,看不到映射的任何问题,甚至在Save方法之前就会引发异常。这个问题与我已经定义的Ordering属性无关。

0 个答案:

没有答案