我正在使用 EF6 alpha 并使用新功能映射到存储过程。在我的单元测试中,我收到错误“过程或函数 CreateDayDetail 指定了太多参数”。
SQL Profiler 显示以下 proc 调用:
exec [Schedule].[CreateDayDetail] @startTime=0,@duration=1,@durationEst=0,@isPaid=1,@requirePunch=0,@dayKey=16,@activityTypeKey=1,@TemplateDay_Key=NULL
问题是自动生成的@TemplateDay_Key 参数。但是,我不确定为什么在没有为 ActivityType 创建一个时创建它。
这是实体类:
public class DayDetail
{
[Key]
public int Key { get; set; }
[Required]
public TemplateDay Day { get; set; }
[Required]
public ActivityType Activity { get; set; }
[Range(TimeMinimum, TimeMaximum)]
public int StartTime { get; set; }
[Range(DurationMinimum, DurationMaximum)]
public int Duration { get; set; }
public bool DurationEstimated { get; set; }
public bool IsPaid { get; set; }
public bool RequirePunch { get; set; }
[Timestamp]
public byte[] Version { get; set; }
}
这是我用来配置模型的 fluent API:
typeConfig.ToTable("Schedule.DayDetail");
typeConfig.Property(d => d.Key)
.HasColumnName("DayDetailKey");
typeConfig.HasRequired(d => d.Day)
.WithMany()
.Map(d => d.MapKey("TemplateDayKey"));
typeConfig.HasRequired(d => d.Activity)
.WithMany()
.Map(d => d.MapKey("ActivityTypeKey"));
typeConfig.MapToStoredProcedures(sp =>
sp.Insert(i => i.HasName("Schedule.CreateDayDetail")
.Parameter(d => d.Day.Key, "dayKey")
.Parameter(d => d.Activity.Key, "activityTypeKey")
.Parameter(d => d.StartTime, "startTime")
.Parameter(d => d.Duration, "duration")
.Parameter(d => d.DurationEstimated, "durationEst")
.Parameter(d => d.IsPaid, "isPaid")
.Parameter(d => d.RequirePunch, "requirePunch"))
.Update(u => u.HasName("Schedule.UpdateDayDetail")
.Parameter(d => d.Key, "key")
.Parameter(d => d.Day.Key, "dayKey")
.Parameter(d => d.Activity.Key, "activityTypeKey")
.Parameter(d => d.StartTime, "startTime")
.Parameter(d => d.Duration, "duration")
.Parameter(d => d.DurationEstimated, "durationEst")
.Parameter(d => d.IsPaid, "isPaid")
.Parameter(d => d.RequirePunch, "requirePunch")
.Parameter(d => d.Version, "version"))
.Delete(x => x.HasName("Schedule.DeleteDayDetail")
.Parameter(d => d.Key, "key")
.Parameter(d => d.Day.Key, "dayKey")
.Parameter(d => d.Activity.Key, "activityTypeKey")
.Parameter(d => d.Version, "version")));
我今天看了这个太久了。我很感激任何帮助.......