简体   繁体   English

使用ID为“ identity(auto_increment)”的LINQ将记录添加到SQL Azure表中

[英]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.

相关问题 使用Entity Framework Core迁移更新表以添加Auto_Increment - Update table with Entity Framework Core migration to add Auto_Increment 是否可以在不使用LINQ to SQL的自动生成类的情况下添加记录? - Is it possible to add record without using the auto generated class in LINQ to SQL? 使用c#更新MySql上的auto_increment ID列的值 - update values of auto_increment ID column on MySql using c# 使用XML作为数据库。 就像我们在SQL中自动递增一样,如何为我的记录生成ID? - Using XML as a database. How to generate id for my record just like we have auto increment in SQL? C#-更新需要猜测AUTO_INCREMENT的ID - C# - Updating an ID that requires guessing an AUTO_INCREMENT 询问创建自己的ID(身份)以在SQL表中添加新记录。 银光 - Ask for the ID (Identity) that created their own to add a new record in an SQL table. Silverlight SQL Server:我如何获得AUTO_INCREMENT状态 - SQL Server : how I get AUTO_INCREMENT status 将sqlce表中的标识设置为自动递增? - Set Identity In sqlce table to auto increment? 使用Linq-to-SQL添加多个记录 - Add Multiple record using Linq-to-SQL 我将如何获取最后一个最大记录ID,增量ID,然后将记录添加到表C#应用程序中 - How would I Get last max record ID,Increment ID and then add record to table C# application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM