C# “在服务中插入方法”;“奥秘”;插入所有内容,但不是我要求的内容
我不能理解这个错误 错误 无,但未插入任何记录。什么也没发生 奥秘 服务“神秘”中的insert方法插入所有内容,但不是我要求它插入的内容 对于customerid值,无论我要求它插入什么,它都会在每次插入中插入数字30118-30119等等 xaml.csC# “在服务中插入方法”;“奥秘”;插入所有内容,但不是我要求的内容,c#,silverlight,insert,C#,Silverlight,Insert,我不能理解这个错误 错误 无,但未插入任何记录。什么也没发生 奥秘 服务“神秘”中的insert方法插入所有内容,但不是我要求它插入的内容 对于customerid值,无论我要求它插入什么,它都会在每次插入中插入数字30118-30119等等 xaml.cs // 公众关于() { 初始化组件(); this.Title=applicationString.AboutPagetTitle; ServiceReference1.Customer new_Customer=新ServiceRefer
//
公众关于()
{
初始化组件();
this.Title=applicationString.AboutPagetTitle;
ServiceReference1.Customer new_Customer=新ServiceReference1.Customer();
//将数据馈送到实例
new_customer.CustomerID=9999999;
new_customer.NameStyle=false;
new_customer.FirstName=“first_name”;
new_customer.LastName=“last_name”;
new\u customer.PasswordHash=“password\u hash”;
new_customer.PasswordSalt=“pass_salt”;
new_customer.rowguid=System.Guid.NewGuid();
new_customer.ModifiedDate=System.DateTime.Now.Date;
ServiceReference1.Service1Client客户端=新的ServiceReference1.Service1Client();
client.DoInsertCompleted+=新系统.EventHandler(client\u DoInsertCompleted);
client.DoInsertAsync(新客户);
}
无效客户端\u DoInsertCompleted(对象发送方,System.ComponentModel.AsyncCompletedEventArgs e)
{
//抛出新系统。NotImplementedException();
标签1.Content=“插入”;
}
svc.cs
namespace BusinessApplication2.Web
{
[ServiceContract(名称空间=”)]
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
公共类服务1
{
[经营合同]
公共列表DoWork()
{
//在此处添加您的操作实现
BusinessApplication2.Web.AdventureWorksLTEntities alpha=新的AdventureWorksLTEntities();
var selected_rows=来自alpha中的行。客户选择行;
返回所选的_行。ToList();
}
[经营合同]
公共void DoInsert(客户alpha)
{
//创建数据库对象
BusinessApplication2.Web.AdventureWorksLTEntities db=新的AdventureWorksLTEntities();
//创建新的表对象
客户新客户=新客户();
new_customer.CustomerID=alpha.CustomerID;
new_customer.NameStyle=alpha.NameStyle;
new_customer.FirstName=alpha.FirstName;
new_customer.LastName=alpha.LastName;
new_customer.PasswordHash=alpha.PasswordHash;
new_customer.PasswordSalt=alpha.PasswordSalt;
new_customer.rowguid=alpha.rowguid;
new_customer.ModifiedDate=alpha.ModifiedDate;
db.Customers.AddObject(新客户);
db.acceptablechanges();
db.SaveChanges();
db.Dispose();
返回;
}//插入到客户端
}
}
您确定没有关闭IdentityInsert吗?请参见已更改的问题?请提供如何关闭或打开。。这样我就可以知道我是否按照你在数据库中说的做了什么,转到CustomerId列并将IdentityInsert更改为on。这将允许您在列中插入ID。如果关闭,数据库引擎将为您执行此操作。设置IDENTITY\u INSERT Table ON,但我不建议这样做。。。除非你真的需要它。以后不要忘记更新您的数据模型。
/// </summary>
public About()
{
InitializeComponent();
this.Title = ApplicationStrings.AboutPageTitle;
ServiceReference1.Customer new_customer = new ServiceReference1.Customer();
//feeding data to the instance
new_customer.CustomerID = 9999999;
new_customer.NameStyle = false;
new_customer.FirstName = "first_name";
new_customer.LastName = "last_name";
new_customer.PasswordHash = "password_hash";
new_customer.PasswordSalt = "pass_salt";
new_customer.rowguid = System.Guid.NewGuid();
new_customer.ModifiedDate = System.DateTime.Now.Date;
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
client.DoInsertCompleted += new System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_DoInsertCompleted);
client.DoInsertAsync(new_customer);
}
void client_DoInsertCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
//throw new System.NotImplementedException();
label1.Content = "Inserted";
}
namespace BusinessApplication2.Web
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
[OperationContract]
public List<Customer> DoWork()
{
// Add your operation implementation here
BusinessApplication2.Web.AdventureWorksLTEntities alpha = new AdventureWorksLTEntities();
var selected_rows = from rows in alpha.Customers select rows;
return selected_rows.ToList();
}
[OperationContract]
public void DoInsert(Customer alpha)
{
//create db object
BusinessApplication2.Web.AdventureWorksLTEntities db = new AdventureWorksLTEntities();
//create a new table object
Customer new_customer = new Customer();
new_customer.CustomerID = alpha.CustomerID;
new_customer.NameStyle = alpha.NameStyle;
new_customer.FirstName = alpha.FirstName;
new_customer.LastName = alpha.LastName;
new_customer.PasswordHash = alpha.PasswordHash;
new_customer.PasswordSalt = alpha.PasswordSalt;
new_customer.rowguid = alpha.rowguid;
new_customer.ModifiedDate = alpha.ModifiedDate;
db.Customers.AddObject(new_customer);
db.AcceptAllChanges();
db.SaveChanges();
db.Dispose();
return;
}//insert to customer ends
}
}