Use stored procedure for search method
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I started with ASP.Net Core 2.0, I'm trying to rewrite a method GetAll
by search use stored procedure. Here is method search:
public async Task<List<DepartmentTypeDto>> SearchDepartmentType()
EnsureConnectionOpen();
using (var command = CreateCommand("CM_DEPT_GROUP_Search", CommandType.StoredProcedure))
using (var dataReader = await command.ExecuteReaderAsync())
List<DepartmentTypeDto> result = new List<DepartmentTypeDto>();
while (dataReader.Read())
DepartmentTypeDto departmentTypeDto = new DepartmentTypeDto
GROUP_ID = dataReader["GROUP_ID"].ToString(),
GROUP_CODE = dataReader["GROUP_CODE"].ToString(),
GROUP_NAME = dataReader["GROUP_NAME"].ToString(),
NOTES = dataReader["NOTES"].ToString(),
RECORD_STATUS = dataReader["RECORD_STATUS"].ToString(),
MAKER_ID = dataReader["MAKER_ID"].ToString(),
CREATE_DT = Convert.ToDateTime(dataReader["CREATE_DT"]),
AUTH_STATUS = dataReader["AUTH_STATUS"].ToString(),
CHECKER_ID = dataReader["CHECKER_ID"].ToString(),
APPROVE_DT = Convert.ToDateTime(dataReader["APPROVE_DT"]),
AUTH_STATUS_NAME = dataReader["AUTH_STATUS_NAME"].ToString(),
RECORD_STATUS_NAME = dataReader["RECORD_STATUS_NAME"].ToString()
;
return result;
Here is the service:
public async Task<PagedResultDto<GetDepartmentTypeForView>> GetAll(GetAllDepartmentTypesInput input)
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType();
var query = (from o in filteredDepartmentTypes
select new GetDepartmentTypeForView() DepartmentType = ObjectMapper.Map<DepartmentTypeDto>(o) );
var totalCount = await query.CountAsync();
var departmentTypes = await query
.OrderBy(input.Sorting ?? "departmentType.id asc")
.PageBy(input)
.ToListAsync();
return new PagedResultDto<GetDepartmentTypeForView>(totalCount, departmentTypes);
But I get an error:
Task<List<DepartmentTypeDto>>
does not contain a definition forSelect
Does anyone know what I should do? I work on Asp.Net Zero.
asp.net stored-procedures asp.net-core
add a comment |
I started with ASP.Net Core 2.0, I'm trying to rewrite a method GetAll
by search use stored procedure. Here is method search:
public async Task<List<DepartmentTypeDto>> SearchDepartmentType()
EnsureConnectionOpen();
using (var command = CreateCommand("CM_DEPT_GROUP_Search", CommandType.StoredProcedure))
using (var dataReader = await command.ExecuteReaderAsync())
List<DepartmentTypeDto> result = new List<DepartmentTypeDto>();
while (dataReader.Read())
DepartmentTypeDto departmentTypeDto = new DepartmentTypeDto
GROUP_ID = dataReader["GROUP_ID"].ToString(),
GROUP_CODE = dataReader["GROUP_CODE"].ToString(),
GROUP_NAME = dataReader["GROUP_NAME"].ToString(),
NOTES = dataReader["NOTES"].ToString(),
RECORD_STATUS = dataReader["RECORD_STATUS"].ToString(),
MAKER_ID = dataReader["MAKER_ID"].ToString(),
CREATE_DT = Convert.ToDateTime(dataReader["CREATE_DT"]),
AUTH_STATUS = dataReader["AUTH_STATUS"].ToString(),
CHECKER_ID = dataReader["CHECKER_ID"].ToString(),
APPROVE_DT = Convert.ToDateTime(dataReader["APPROVE_DT"]),
AUTH_STATUS_NAME = dataReader["AUTH_STATUS_NAME"].ToString(),
RECORD_STATUS_NAME = dataReader["RECORD_STATUS_NAME"].ToString()
;
return result;
Here is the service:
public async Task<PagedResultDto<GetDepartmentTypeForView>> GetAll(GetAllDepartmentTypesInput input)
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType();
var query = (from o in filteredDepartmentTypes
select new GetDepartmentTypeForView() DepartmentType = ObjectMapper.Map<DepartmentTypeDto>(o) );
var totalCount = await query.CountAsync();
var departmentTypes = await query
.OrderBy(input.Sorting ?? "departmentType.id asc")
.PageBy(input)
.ToListAsync();
return new PagedResultDto<GetDepartmentTypeForView>(totalCount, departmentTypes);
But I get an error:
Task<List<DepartmentTypeDto>>
does not contain a definition forSelect
Does anyone know what I should do? I work on Asp.Net Zero.
asp.net stored-procedures asp.net-core
2
Before_departmentTypeRepository.SearchDepartmentType()
try to putawait
keyword.
– Arsiwaldi
Nov 14 '18 at 8:37
1
I started with ASP.Net Core 2.0
So, why don't you use Entity Framework? You can take a tour here: Get started with ASP.NET Core
– Foo
Nov 14 '18 at 9:07
@TânNguyễn sếp bảo làm cách này anh :D. I use FromSql and It works. Btw Hope to receive your help in the future if it possible
– baonhg
Nov 27 '18 at 8:26
add a comment |
I started with ASP.Net Core 2.0, I'm trying to rewrite a method GetAll
by search use stored procedure. Here is method search:
public async Task<List<DepartmentTypeDto>> SearchDepartmentType()
EnsureConnectionOpen();
using (var command = CreateCommand("CM_DEPT_GROUP_Search", CommandType.StoredProcedure))
using (var dataReader = await command.ExecuteReaderAsync())
List<DepartmentTypeDto> result = new List<DepartmentTypeDto>();
while (dataReader.Read())
DepartmentTypeDto departmentTypeDto = new DepartmentTypeDto
GROUP_ID = dataReader["GROUP_ID"].ToString(),
GROUP_CODE = dataReader["GROUP_CODE"].ToString(),
GROUP_NAME = dataReader["GROUP_NAME"].ToString(),
NOTES = dataReader["NOTES"].ToString(),
RECORD_STATUS = dataReader["RECORD_STATUS"].ToString(),
MAKER_ID = dataReader["MAKER_ID"].ToString(),
CREATE_DT = Convert.ToDateTime(dataReader["CREATE_DT"]),
AUTH_STATUS = dataReader["AUTH_STATUS"].ToString(),
CHECKER_ID = dataReader["CHECKER_ID"].ToString(),
APPROVE_DT = Convert.ToDateTime(dataReader["APPROVE_DT"]),
AUTH_STATUS_NAME = dataReader["AUTH_STATUS_NAME"].ToString(),
RECORD_STATUS_NAME = dataReader["RECORD_STATUS_NAME"].ToString()
;
return result;
Here is the service:
public async Task<PagedResultDto<GetDepartmentTypeForView>> GetAll(GetAllDepartmentTypesInput input)
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType();
var query = (from o in filteredDepartmentTypes
select new GetDepartmentTypeForView() DepartmentType = ObjectMapper.Map<DepartmentTypeDto>(o) );
var totalCount = await query.CountAsync();
var departmentTypes = await query
.OrderBy(input.Sorting ?? "departmentType.id asc")
.PageBy(input)
.ToListAsync();
return new PagedResultDto<GetDepartmentTypeForView>(totalCount, departmentTypes);
But I get an error:
Task<List<DepartmentTypeDto>>
does not contain a definition forSelect
Does anyone know what I should do? I work on Asp.Net Zero.
asp.net stored-procedures asp.net-core
I started with ASP.Net Core 2.0, I'm trying to rewrite a method GetAll
by search use stored procedure. Here is method search:
public async Task<List<DepartmentTypeDto>> SearchDepartmentType()
EnsureConnectionOpen();
using (var command = CreateCommand("CM_DEPT_GROUP_Search", CommandType.StoredProcedure))
using (var dataReader = await command.ExecuteReaderAsync())
List<DepartmentTypeDto> result = new List<DepartmentTypeDto>();
while (dataReader.Read())
DepartmentTypeDto departmentTypeDto = new DepartmentTypeDto
GROUP_ID = dataReader["GROUP_ID"].ToString(),
GROUP_CODE = dataReader["GROUP_CODE"].ToString(),
GROUP_NAME = dataReader["GROUP_NAME"].ToString(),
NOTES = dataReader["NOTES"].ToString(),
RECORD_STATUS = dataReader["RECORD_STATUS"].ToString(),
MAKER_ID = dataReader["MAKER_ID"].ToString(),
CREATE_DT = Convert.ToDateTime(dataReader["CREATE_DT"]),
AUTH_STATUS = dataReader["AUTH_STATUS"].ToString(),
CHECKER_ID = dataReader["CHECKER_ID"].ToString(),
APPROVE_DT = Convert.ToDateTime(dataReader["APPROVE_DT"]),
AUTH_STATUS_NAME = dataReader["AUTH_STATUS_NAME"].ToString(),
RECORD_STATUS_NAME = dataReader["RECORD_STATUS_NAME"].ToString()
;
return result;
Here is the service:
public async Task<PagedResultDto<GetDepartmentTypeForView>> GetAll(GetAllDepartmentTypesInput input)
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType();
var query = (from o in filteredDepartmentTypes
select new GetDepartmentTypeForView() DepartmentType = ObjectMapper.Map<DepartmentTypeDto>(o) );
var totalCount = await query.CountAsync();
var departmentTypes = await query
.OrderBy(input.Sorting ?? "departmentType.id asc")
.PageBy(input)
.ToListAsync();
return new PagedResultDto<GetDepartmentTypeForView>(totalCount, departmentTypes);
But I get an error:
Task<List<DepartmentTypeDto>>
does not contain a definition forSelect
Does anyone know what I should do? I work on Asp.Net Zero.
asp.net stored-procedures asp.net-core
asp.net stored-procedures asp.net-core
edited Nov 14 '18 at 9:23
marc_s
586k13011281272
586k13011281272
asked Nov 14 '18 at 8:24
baonhgbaonhg
64
64
2
Before_departmentTypeRepository.SearchDepartmentType()
try to putawait
keyword.
– Arsiwaldi
Nov 14 '18 at 8:37
1
I started with ASP.Net Core 2.0
So, why don't you use Entity Framework? You can take a tour here: Get started with ASP.NET Core
– Foo
Nov 14 '18 at 9:07
@TânNguyễn sếp bảo làm cách này anh :D. I use FromSql and It works. Btw Hope to receive your help in the future if it possible
– baonhg
Nov 27 '18 at 8:26
add a comment |
2
Before_departmentTypeRepository.SearchDepartmentType()
try to putawait
keyword.
– Arsiwaldi
Nov 14 '18 at 8:37
1
I started with ASP.Net Core 2.0
So, why don't you use Entity Framework? You can take a tour here: Get started with ASP.NET Core
– Foo
Nov 14 '18 at 9:07
@TânNguyễn sếp bảo làm cách này anh :D. I use FromSql and It works. Btw Hope to receive your help in the future if it possible
– baonhg
Nov 27 '18 at 8:26
2
2
Before
_departmentTypeRepository.SearchDepartmentType()
try to put await
keyword.– Arsiwaldi
Nov 14 '18 at 8:37
Before
_departmentTypeRepository.SearchDepartmentType()
try to put await
keyword.– Arsiwaldi
Nov 14 '18 at 8:37
1
1
I started with ASP.Net Core 2.0
So, why don't you use Entity Framework? You can take a tour here: Get started with ASP.NET Core– Foo
Nov 14 '18 at 9:07
I started with ASP.Net Core 2.0
So, why don't you use Entity Framework? You can take a tour here: Get started with ASP.NET Core– Foo
Nov 14 '18 at 9:07
@TânNguyễn sếp bảo làm cách này anh :D. I use FromSql and It works. Btw Hope to receive your help in the future if it possible
– baonhg
Nov 27 '18 at 8:26
@TânNguyễn sếp bảo làm cách này anh :D. I use FromSql and It works. Btw Hope to receive your help in the future if it possible
– baonhg
Nov 27 '18 at 8:26
add a comment |
1 Answer
1
active
oldest
votes
I changed my search method
public IQueryable<DepartmentTypeView> SearchDepartmentType(GetAllDepartmentTypesInput input, int top)
try
var GROUP_FILTER = input.Filter;
var GROUP_CODE = input.GROUP_CODEFilter;
var GROUP_NAME = input.GROUP_NAMEFilter;
var AUTH_STATUS = input.AUTH_STATUSFilter;
var result = Context.Query<DepartmentTypeView>().FromSql($"EXEC CM_DEPT_GROUP_Search @p_GROUP_FILTER = GROUP_FILTER, @p_GROUP_CODE=GROUP_CODE, @p_GROUP_NAME=GROUP_NAME, @p_AUTH_STATUS=AUTH_STATUS, @p_TOP=top");
return result;
catch
return null;
and in the service, I call that function
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType(input,100);
I also create new class to keep the result and don't forget to map that class with DTO class
configuration.CreateMap<DepartmentTypeView, DepartmentTypeDto>();
It works for me.
Mark your answer as accepted.
– aaron
Dec 10 '18 at 18:11
Mark your answer as accepted.
– aaron
Jan 1 at 5:00
Mark your answer as accepted.
– aaron
Feb 3 at 3:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295793%2fuse-stored-procedure-for-search-method%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I changed my search method
public IQueryable<DepartmentTypeView> SearchDepartmentType(GetAllDepartmentTypesInput input, int top)
try
var GROUP_FILTER = input.Filter;
var GROUP_CODE = input.GROUP_CODEFilter;
var GROUP_NAME = input.GROUP_NAMEFilter;
var AUTH_STATUS = input.AUTH_STATUSFilter;
var result = Context.Query<DepartmentTypeView>().FromSql($"EXEC CM_DEPT_GROUP_Search @p_GROUP_FILTER = GROUP_FILTER, @p_GROUP_CODE=GROUP_CODE, @p_GROUP_NAME=GROUP_NAME, @p_AUTH_STATUS=AUTH_STATUS, @p_TOP=top");
return result;
catch
return null;
and in the service, I call that function
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType(input,100);
I also create new class to keep the result and don't forget to map that class with DTO class
configuration.CreateMap<DepartmentTypeView, DepartmentTypeDto>();
It works for me.
Mark your answer as accepted.
– aaron
Dec 10 '18 at 18:11
Mark your answer as accepted.
– aaron
Jan 1 at 5:00
Mark your answer as accepted.
– aaron
Feb 3 at 3:14
add a comment |
I changed my search method
public IQueryable<DepartmentTypeView> SearchDepartmentType(GetAllDepartmentTypesInput input, int top)
try
var GROUP_FILTER = input.Filter;
var GROUP_CODE = input.GROUP_CODEFilter;
var GROUP_NAME = input.GROUP_NAMEFilter;
var AUTH_STATUS = input.AUTH_STATUSFilter;
var result = Context.Query<DepartmentTypeView>().FromSql($"EXEC CM_DEPT_GROUP_Search @p_GROUP_FILTER = GROUP_FILTER, @p_GROUP_CODE=GROUP_CODE, @p_GROUP_NAME=GROUP_NAME, @p_AUTH_STATUS=AUTH_STATUS, @p_TOP=top");
return result;
catch
return null;
and in the service, I call that function
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType(input,100);
I also create new class to keep the result and don't forget to map that class with DTO class
configuration.CreateMap<DepartmentTypeView, DepartmentTypeDto>();
It works for me.
Mark your answer as accepted.
– aaron
Dec 10 '18 at 18:11
Mark your answer as accepted.
– aaron
Jan 1 at 5:00
Mark your answer as accepted.
– aaron
Feb 3 at 3:14
add a comment |
I changed my search method
public IQueryable<DepartmentTypeView> SearchDepartmentType(GetAllDepartmentTypesInput input, int top)
try
var GROUP_FILTER = input.Filter;
var GROUP_CODE = input.GROUP_CODEFilter;
var GROUP_NAME = input.GROUP_NAMEFilter;
var AUTH_STATUS = input.AUTH_STATUSFilter;
var result = Context.Query<DepartmentTypeView>().FromSql($"EXEC CM_DEPT_GROUP_Search @p_GROUP_FILTER = GROUP_FILTER, @p_GROUP_CODE=GROUP_CODE, @p_GROUP_NAME=GROUP_NAME, @p_AUTH_STATUS=AUTH_STATUS, @p_TOP=top");
return result;
catch
return null;
and in the service, I call that function
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType(input,100);
I also create new class to keep the result and don't forget to map that class with DTO class
configuration.CreateMap<DepartmentTypeView, DepartmentTypeDto>();
It works for me.
I changed my search method
public IQueryable<DepartmentTypeView> SearchDepartmentType(GetAllDepartmentTypesInput input, int top)
try
var GROUP_FILTER = input.Filter;
var GROUP_CODE = input.GROUP_CODEFilter;
var GROUP_NAME = input.GROUP_NAMEFilter;
var AUTH_STATUS = input.AUTH_STATUSFilter;
var result = Context.Query<DepartmentTypeView>().FromSql($"EXEC CM_DEPT_GROUP_Search @p_GROUP_FILTER = GROUP_FILTER, @p_GROUP_CODE=GROUP_CODE, @p_GROUP_NAME=GROUP_NAME, @p_AUTH_STATUS=AUTH_STATUS, @p_TOP=top");
return result;
catch
return null;
and in the service, I call that function
var filteredDepartmentTypes = _departmentTypeRepository.SearchDepartmentType(input,100);
I also create new class to keep the result and don't forget to map that class with DTO class
configuration.CreateMap<DepartmentTypeView, DepartmentTypeDto>();
It works for me.
answered Dec 10 '18 at 14:35
baonhgbaonhg
64
64
Mark your answer as accepted.
– aaron
Dec 10 '18 at 18:11
Mark your answer as accepted.
– aaron
Jan 1 at 5:00
Mark your answer as accepted.
– aaron
Feb 3 at 3:14
add a comment |
Mark your answer as accepted.
– aaron
Dec 10 '18 at 18:11
Mark your answer as accepted.
– aaron
Jan 1 at 5:00
Mark your answer as accepted.
– aaron
Feb 3 at 3:14
Mark your answer as accepted.
– aaron
Dec 10 '18 at 18:11
Mark your answer as accepted.
– aaron
Dec 10 '18 at 18:11
Mark your answer as accepted.
– aaron
Jan 1 at 5:00
Mark your answer as accepted.
– aaron
Jan 1 at 5:00
Mark your answer as accepted.
– aaron
Feb 3 at 3:14
Mark your answer as accepted.
– aaron
Feb 3 at 3:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295793%2fuse-stored-procedure-for-search-method%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Before
_departmentTypeRepository.SearchDepartmentType()
try to putawait
keyword.– Arsiwaldi
Nov 14 '18 at 8:37
1
I started with ASP.Net Core 2.0
So, why don't you use Entity Framework? You can take a tour here: Get started with ASP.NET Core– Foo
Nov 14 '18 at 9:07
@TânNguyễn sếp bảo làm cách này anh :D. I use FromSql and It works. Btw Hope to receive your help in the future if it possible
– baonhg
Nov 27 '18 at 8:26