[英]Add record to an SQL Azure table using LINQ where ID is “identity (auto_increment)”
I am trying to pass a LINQ query in my Service1.svc.cs to add a new Asset which is an entity in my SQL Azure database. 我正在尝试在Service1.svc.cs中传递LINQ查询,以添加一个新资产,该资产是SQL Azure数据库中的一个实体。 Also AstID is the PK and is set as identity in SQL Azure
AstID也是PK,并且在SQL Azure中设置为身份
I have an OperationContract
as follows in my IService1.cs 我的IService1.cs中有一个
OperationContract
,如下所示
[OperationContract]
void AddAsset(string AstName, string AstCondition);
and the following void in my Service1.cs 和以下在我的Service1.cs中无效
public void AddAsset(string AstName, string AstCondition)
{
DataClasses1DataContext context = new DataClasses1DataContext();
Asset AssetObj = new Asset();
AssetObj.AstName = AstName;
AssetObj.AstCondition = AstCondition;
context.Assets.InsertOnSubmit(AssetObj);
context.SubmitChanges();
}
In my Client Application, where i'm consuming the WCF Service, i have the following: 在我使用WCF服务的客户端应用程序中,我具有以下内容:
public void AddAssetQuery(string AstName, string AstCondition)
{
Service1Client proxy = new Service1Client();
proxy.AddAssetCompleted += (proxy_AddAssetCompleted);
proxy.AddAssetAsync(AstName, AstCondition);
}
and 和
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
AddAssetQuery("Dell PC","Mint");
}
I also have a Completed void, wherein i have a MessageBox that notifies me that the action was completed. 我还有一个Completed void,其中有一个MessageBox通知我该操作已完成。 Even though, when i check my SQL Azure databse, no data is being fed.
即使,当我检查我的SQL Azure数据库时,也没有数据被送入。 Any ideas, why?
有什么想法,为什么?
Try: 尝试:
public void AddAsset(string AstName, string AstCondition)
{
DataClasses1DataContext context = new DataClasses1DataContext();
Asset AssetObj = new Asset();
AssetObj.AstName = AstName;
AssetObj.AstCondition = AstCondition;
context.Assets.Add(AssetObj);
context.SaveChanges();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.