Reputation: 671
My stored procedure is
Create proc [dbo].[InsertPerson]
(
@LastName VARCHAR(64),
@FirstName VARCHAR(64),
@Age INT
)
AS
INSERT INTO Person Values(@LastName,@FirstName,@Age)
The save method of the BaseRepository class is as follows:
public virtual int Add(string storedProcedure, T entity, IDbTransaction transaction)
{
var i = 0;
try
{
if (entity == null)
throw new ArgumentNullException("entity", "Add to DB null entity");
var parameters = (object)Mapping(entity);
i = _conn.Execute(storedProcedure, parameters, transaction, commandType: CommandType.StoredProcedure);
}
catch (Exception ex)
{
throw ex;
}
return i;
}
The map method is as follows:
internal virtual dynamic Mapping(T entity)
{
return entity;
}
The definition of PersonRepository class is as follows:
public class PersonRepository:DapperRepository<Person>, IPersonRepository
{
public PersonRepository(IUnitOfWork uow) : base(uow) { }
internal override dynamic Mapping(Person person)
{
return new {person.LastName, person.FristName, person.Age };
}
}
My Service class I declared Save method as follows:
public void Save(Person person)
{
try
{
string sp = "InsertPerson";
_repository.Add(sp, person, _unitOfWork.BeginTransaction());
_unitOfWork.Commit();
}
catch (Exception)
{
throw;
}
}
When I am trying to execute my Save method it shows me following exception:
Procedure or function 'InsertPerson' expects parameter '@FirstName', which was not supplied.
Upvotes: 1
Views: 876
Reputation: 6656
There is spell mistake in your property name
person.FristName
it should be
person.FirstName
So now your mapping function should look like this
internal override dynamic Mapping(Person person)
{
return new {person.LastName, person.FirstName, person.Age };
}
Upvotes: 2