Insert into SQL database with return inserted id through Insight Database ORM

By 12th April 2019Insight Database

First of all you should add reference of insight datatabse from nuget package manager. command bellow :

Install-Package Insight.Database -Version 6.2.8

After that just include namespace of insight database .

using Insight.Database;

Query :

these are the paramaeters which we will pass in insert query values

               var parameters = new
                            Name= model.Name,
                            StreetAddress = model.StreetAddress,
                            City = model.City,
                            State = model.State,
                            Zip = model.Zip,
                            PhoneNo = model.PhoneNo,
decimal InsertedId = DB.ExecuteScalarSql<decimal>(@"INSERT INTO [dbo]. 
                                 ) SELECT @@IDENTITY", parameters);

it will return the inserted id in InsertedId variable.