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

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

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]. 
                                                            [tbl_USER]
                                                           (Name
                                                         ,StreetAddress
                                                           ,City
                                                           ,State
                                                           ,Zip
                                                           ,PhoneNo)
                                                         VALUES
                                                           (@Name 
                                                        ,@StreetAddress
                                                           ,@City
                                                           ,@State
                                                           ,@Zip 
                                                           ,@PhoneNo 
                                 ) SELECT @@IDENTITY", parameters);

it will return the inserted id in InsertedId variable.