如何使用实体框架将表值分配给存储过程参数



我使用角度将 Html 表值发送到 mvc 控制器操作方法。这是我的角度代码。

      var feedbackdata = {
        SpeakerRatings: $scope.SpeakerTable  // This scope contains two rows of table data
    };
    FeedBackFormfac.InsertFeedback(feedbackdata).then(function (data) {
        alert(data.data)
    })
  fac.InsertFeedback = function (d) {
    return $http({
        url: '/Feedback/Insert',
        method: 'POST',
        data: JSON.stringify(d),
        headers: {'content-type': 'application/json'}
    });
};

我在我的控制器操作方法中接收此 json 数据。我试图使用实体框架将这些数据插入我的数据库中。但我无法将表值绑定到参数扬声器评级。

  public JsonResult Insert(FeedBackFormVM F)
    {
          var procedure = new InsertFeedbackSP()
            {
               SpeakerRatings = new List<SpeakerRatingsUDT>
               {
                   new SpeakerRatingsUDT()
               }
            }
    }

在上面的代码中,im试图将来自角度的数据绑定到使用entityframeworkextra创建的用户定义表类型类,我的用户定义表类将是这样的

 [UserDefinedTableType("SpeakerRatingsType")]
public class SpeakerRatingsUDT
{
    [UserDefinedTableTypeColumn(1)]
    public int SpeakerId { get; set; }
    [UserDefinedTableTypeColumn(2)]
    public string SpeakerName { get; set; }
    [UserDefinedTableTypeColumn(3)]
    public int Rating { get; set; } 
} 
我正在

将 Html 表值接收到具有 UserdefinedType 类类型的列表中

   public JsonResult Insert(FeedBackFormVM F)
    {
          List<SpeakerRatingsVM> newdata = F.SpeakerRatings;
          var procedure = new InsertFeedbackSP()
            {
               SpeakerRatings = newdata.Select(x => new SpeakerRatingsUDT { 
      SpeakerId=x.SpeakerId,SpeakerName=x.SpeakerName,Rating=x.Rating}).ToList()
            }
    }

最新更新