【问题标题】:Entity Framework - Insert Object with multiple related objects实体框架 - 插入具有多个相关对象的对象
【发布时间】:2014-01-09 22:00:38
【问题描述】:

我正在尝试通过 WCF 服务调用插入新的 [Shows] 记录,该记录与 [Performances] 具有一对多关系。

[Shows] 记录已创建,但 [Performances] 记录未创建。没有错误被抛出。我怎样才能同时创建绩效记录?

客户

 Dim oShow As New Show With
            {
              'Properties here...
            }

    Dim cPerformances As New Collections.ObjectModel.Collection(Of Performance)

    cPerformances.Add(New Performance With
                      {
                          'Properties here...
                      })
    cPerformances.Add(New Performance With
                     {
                          'Properties here...
                     })

    oShow.Performances = cPerformances

        Dim myServiceRef As New myWCFService.ServiceName
        myServiceRef.CreateShow(oShow)

服务

        Dim ctx As New myEntities(ServiceURI)

        ctx.AddToShows(oShow)
        ctx.SaveChanges()

【问题讨论】:

  • 在调用 SaveChanges() 之前,您是否看到调试器中服务端正确填充了性能?
  • 是的,如果我单步执行ctx.AddToshows(oShow),那么所有属性和 2 个 Performance 对象都在那里。仅创建 Show 记录。
  • 您必须手动创建它们,也可能通过 Performance 属性来创建。
  • @DonA - 根据这个链接和我能在上面找到的所有其他线程,它应该自动执行此操作 - stackoverflow.com/questions/19546475/…

标签: .net vb.net wcf entity-framework


【解决方案1】:

我删除并重新创建了 edmx,现在正在插入相关对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多