3

I have a SQL script that when run, inserts rows in 2 tables. How can I access the Ids of newly inserted rows in Npoco. Here is what my SQL looks like:

DECLARE @@clientId TABLE (Id INT);

INSERT [dbo].[Clients] ([FirstName], [LastName])
OUTPUT INSERTED.clientId INTO @@clientId 
VALUES ( N'John', N'Doe');

SELECT Id FROM @@clientId;

How can I access the selected data in last line, in NPoco using C# ?

Farooq Hanif
  • 1,779
  • 1
  • 15
  • 22

2 Answers2

2

It should auto updated in client object. I have worked in Nhibernate and EF. It should work for NPoco as well.

    public void AddClient(Client client)  
    {  
        connection.Insert<Client>(client);
        //after save client.Id.


    }
Deepak Kumar
  • 648
  • 6
  • 14
0

How are you running the script with NPoco? Maybe something like this?

var RC = Database.Fetch<List<int>>(SQL);
JAZ
  • 1,050
  • 6
  • 15