0
`我有下面的實體框架4.1模型。WCF和實體框架4.1 POCO
public partial class AWLTR2Model : DbContext
{
public AWLTR2Model()
: base("name=AWLTR2Model")
{
Configuration.ProxyCreationEnabled = false;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Address> Addresses { get; set; }
public DbSet<Customer> Customers { get; set; }
public DbSet<CustomerAddress> CustomerAddresses { get; set; }
}
我有下面這是在不同的命名空間AWLTR2.Entity
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
public partial class CustomerAddress
{
public int CustomerID { get; set; }
public int AddressID { get; set; }
public string AddressType { get; set; }
public System.Guid rowguid { get; set; }
public System.DateTime ModifiedDate { get; set; }
public virtual Address Address { get; set; }
public virtual Customer Customer { get; set; }
}
我暴露通過WCF服務,這些實體(basicHttpBinding的),但在我的客戶,我無法添加POCO實體子實體與下面的父實體相似。
Customer c = new Customer
{
FirstName = "xx",
CompanyName = "zz",
EmailAddress = "[email protected]",
LastName = "yy",
ModifiedDate = DateTime.Now,
NameStyle = false,
PasswordHash = "abcd",
PasswordSalt = "abcd",
Phone = "xx",
rowguid = System.Guid.NewGuid()
};
CustomerAddress ca = new CustomerAddress
{
AddressID = 9 ,
Customer = c ,
AddressType ="Home Office",
ModifiedDate=System.DateTime.Now,
rowguid = System.Guid.NewGuid()
};
客戶端中缺少add方法,但我能夠在不公開WCF的情況下執行此操作。如下所示: 。 c.CustomerAddresses.Add(ca);
我想寫一個方法來一次添加客戶以及地址和客戶地址。我使用實體框架4.0與對象上下文一樣實現了同樣的功能。但在Dbcontext中無法這樣做。
任何線索?
謝謝Ladislav Mrnka。有效!!!呼... – 2012-03-05 10:24:09