Skip to content

Instantly share code, notes, and snippets.

@hendrasyp
Created April 1, 2024 03:37
Show Gist options
  • Save hendrasyp/e4e5452b8878b5a4de362135bbf49a72 to your computer and use it in GitHub Desktop.
Save hendrasyp/e4e5452b8878b5a4de362135bbf49a72 to your computer and use it in GitHub Desktop.
Execute Stored Procedure
public interface IService{
public Task<MyModel> Get_MyMethod();
}
public class Service : IService {
public async Task<MyModel> Get_MyMethod(){
// 1. Buat list parameter
List<SqlParam> parameters = new List<SqlParam>();
parameters.Add(new SqlParam { ParamType = DataTypeConstant.NUMERIC, ParamValue = partnerKey }); // @ID
// 2. Jika hasil akan ditampung dalam model
MyModel myModel = new MyModel();
List<MyModel> myModelList = RepositoryHelper.Execute<MyModel>(_options, "NAMA_SEP", parameters);
// 2.A Jika hasil akan ditampung dalam list dictionary
MyModel myModel = new MyModel();
List<Dictionary<string, dynamic>> myModelList = RepositoryHelper.Execute<Dictionary<string, dynamic>>(_options, "NAMA_SEP", parameters);
// 3. Logic tambahan (jika ada)
if (myModelList.Count > 0)
{
myModel = myModelList[0];
}
return await Task.FromResult(myModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment