【发布时间】:2015-12-31 12:51:58
【问题描述】:
我有 Web 服务和一个方法,它使用实体框架向我的表“客户”发出请求。
我想返回我的请求的结果:
[WebMethod]
public Customer MyMethod(int id)
{
Model model = new Model();
Customer customer = new Customer();
try
{
customer = model.Customer.Where(x => x.Name == id).First();
}
catch (Exception ex)
{
throw new System.NullReferenceException(ex.Message, ex.InnerException);
}
return customer;
}
我的班级客户(由 EF 生成):
[Table("Customer")]
public partial class Customer
{
public int Id { get; set; }
[StringLength(50)]
public string Name { get; set; }
public int? Adress_id { get; set; }
public virtual Adress Adress { get; set; }
}
类地址(由 EF 生成):
[Table("Adress")]
public partial class Adress
{
public Adress()
{
Customer = new HashSet<Customer>();
}
public int Id { get; set; }
[Column("Adress")]
[StringLength(255)]
public string Adress1 { get; set; }
[StringLength(50)]
public string Town { get; set; }
public virtual ICollection<Customer> Customer{ get; set; }
}
但是当我使用 SoapUI 调用我的方法时,我没有答案。如果我删除属性 virtual Adress 那么我有一个答案,但我还需要取回地址(联合)
谢谢
【问题讨论】:
-
猜你的型号是
dbcontext换行model.Customer.include("Adress ").Where(x => x.Name == id).First() -
是一样的,修改行没有答案
-
你能解释一下你需要什么吗?
-
返回我的查询结果。客户+地址
-
您确定您的数据库中有与该客户相关的地址吗?
标签: c# entity-framework wcf