我是网络服务运营的新手。我正在尝试为我的android app.Solution工作创建搜索或列表操作的Web服务,但问题是我无法发送给对象客户
这些是我的模型,他们映射:
[WebInvoke(Method = "POST",
UriTemplate = "CreateCustomer/",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json )]
public Customer CreateCustomer(Customer customer)
{
//Customer customer = JsonConvert.DeserializeObject<Customer>(CustomerJson);
if(customer == null)
{
throw new ArgumentNullException("FAIL");
}
CustomerManager cm = new CustomerManager();
cm.CreateCustomer(customer);
return customer;
}
我尝试这种方法,但它不起作用
public Customer CreateCustomer(Customer customer)
{
ISession session = this.GetSession();
using (var tx = session.BeginTransaction())
{
try
{
this.GetSession().Save(customer); //new NHibernateSessionManager().GetSession();
this.GetSession().Save(customer.Addresses);
tx.Commit();
}
catch
{
tx.Rollback();
}
}
return customer;
}
这是我使用Nhibernate的Create方法
B2
thanx征求意见。
答案 0 :(得分:0)
不应该CreateCustomer()
方法看起来像这样:
public Customer CreateCustomer(Customer customer)
{
using (var session = this.GetSession())
using (var tx = session.BeginTransaction())
{
try
{
session.Save(customer);
session.Save(customer.Addresses); // This could be omitted with cascade
tx.Commit();
}
catch
{
tx.Rollback();
}
}
return customer;
}