FluentData 3.0 Error - ExecuteReturnLastId<T>() Function

Feb 19, 2013 at 5:42 AM
The below query
int productId = 
                   objDbContext.Sql(@"insert into Product(ProductId,ProductName,Price) 
                       values(@0, @1,@2 )")
                    .Parameters(100011,"sampleData", 2)
                    .ExecuteReturnLastId<Int32>();
returns "Index was outside the bounds of the array" Exception. can anybody help me why this error is occurring.
Coordinator
Mar 5, 2013 at 7:02 PM
In your product table, is the ProductId field an identity field?

If yes, then you need to use this code:

int productId =
               objDbContext.Sql(@"insert into Product(ProductName,Price) 
                   values(@0, @1)")
                .Parameters("sampleData", 2)
                .ExecuteReturnLastId<Int32>();
If no, use this code:
               objDbContext.Sql(@"insert into Product(ProductId,ProductName,Price) 
                   values(@0, @1,@2 )")
                .Parameters(100011,"sampleData", 2)
                .Execute();
Did this help?