我试图在我的Service1.svc.cs中传递LINQ查询,以添加一个新的资产,这是我的SQL Azure数据库中的一个实体。另外,AstID是PK,在SQL Azure
中设置为身份。我有一个OperationContract
如下在我的IService1.cs
[OperationContract]
void AddAsset(string AstName, string AstCondition);
和我的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();
}
在我的客户端应用程序中,我正在使用WCF服务,我有以下内容:
public void AddAssetQuery(string AstName, string AstCondition)
{
Service1Client proxy = new Service1Client();
proxy.AddAssetCompleted += (proxy_AddAssetCompleted);
proxy.AddAssetAsync(AstName, AstCondition);
}
和
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
AddAssetQuery("Dell PC","Mint");
}
我也有一个Completed void,其中我有一个MessageBox,通知我操作已经完成。即使,当我检查我的SQL Azure数据库,没有数据被馈送。任何想法,为什么?
尝试:
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();
}