How to work with data that gets returned by an IEnumerable method












0














I'm trying to create a simple view (paging, sorting and filtering).
The method I have that does that looks something like this:



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, 
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
var data = _makeRepository.SelectListMake(index, count, orderLambda).AsQueryable();
return data;
}


You see it call another method from a repository, which looks the same



private readonly IQueryable<VehicleMakeEntity> _source;

public MakeRepository(ProjectDbContext context)
{
this.context = context;
_source = this.context.VehicleMake;
}

public IEnumerable<VehicleMakeEntity> SelectListMake(int index, int count,
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _source.Skip(index * count).Take(count).OrderBy(orderLambda);
}


In my controller I call the method



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id));

return View(data);
}


And it returns some data I do not know how to work with as seen here





I also generated a View based on that controller method, a basic List View which you can see here



@model IEnumerable<Data.Entities.VehicleMakeEntity>
@using NonFactors.Mvc.Grid;
@{
ViewData["Title"] = "Make View";
}
<h2>Make View</h2>

<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Abrv)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Abrv)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</tbody>




But nothing is displaying on the site. Am I supposed to do something with the returned data? What am I doing wrong? I checked if the entities aren't getting the information from the database, they are.










share|improve this question




















  • 2




    How many records are in your db (your code returns records 11 to 20). And as a side note, your .OrderBy() should be before .Skip()
    – user3559349
    Nov 20 at 5:34












  • So that was the problem. But why does it do that? I thought the second parameter limited how many records it pulls at a given time.
    – TimmyNeutron
    Nov 20 at 5:41












  • Because index=1 and .Skip(index * count) equates to .Skip(10) which means start at record number 11
    – user3559349
    Nov 20 at 5:52
















0














I'm trying to create a simple view (paging, sorting and filtering).
The method I have that does that looks something like this:



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, 
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
var data = _makeRepository.SelectListMake(index, count, orderLambda).AsQueryable();
return data;
}


You see it call another method from a repository, which looks the same



private readonly IQueryable<VehicleMakeEntity> _source;

public MakeRepository(ProjectDbContext context)
{
this.context = context;
_source = this.context.VehicleMake;
}

public IEnumerable<VehicleMakeEntity> SelectListMake(int index, int count,
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _source.Skip(index * count).Take(count).OrderBy(orderLambda);
}


In my controller I call the method



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id));

return View(data);
}


And it returns some data I do not know how to work with as seen here





I also generated a View based on that controller method, a basic List View which you can see here



@model IEnumerable<Data.Entities.VehicleMakeEntity>
@using NonFactors.Mvc.Grid;
@{
ViewData["Title"] = "Make View";
}
<h2>Make View</h2>

<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Abrv)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Abrv)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</tbody>




But nothing is displaying on the site. Am I supposed to do something with the returned data? What am I doing wrong? I checked if the entities aren't getting the information from the database, they are.










share|improve this question




















  • 2




    How many records are in your db (your code returns records 11 to 20). And as a side note, your .OrderBy() should be before .Skip()
    – user3559349
    Nov 20 at 5:34












  • So that was the problem. But why does it do that? I thought the second parameter limited how many records it pulls at a given time.
    – TimmyNeutron
    Nov 20 at 5:41












  • Because index=1 and .Skip(index * count) equates to .Skip(10) which means start at record number 11
    – user3559349
    Nov 20 at 5:52














0












0








0







I'm trying to create a simple view (paging, sorting and filtering).
The method I have that does that looks something like this:



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, 
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
var data = _makeRepository.SelectListMake(index, count, orderLambda).AsQueryable();
return data;
}


You see it call another method from a repository, which looks the same



private readonly IQueryable<VehicleMakeEntity> _source;

public MakeRepository(ProjectDbContext context)
{
this.context = context;
_source = this.context.VehicleMake;
}

public IEnumerable<VehicleMakeEntity> SelectListMake(int index, int count,
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _source.Skip(index * count).Take(count).OrderBy(orderLambda);
}


In my controller I call the method



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id));

return View(data);
}


And it returns some data I do not know how to work with as seen here





I also generated a View based on that controller method, a basic List View which you can see here



@model IEnumerable<Data.Entities.VehicleMakeEntity>
@using NonFactors.Mvc.Grid;
@{
ViewData["Title"] = "Make View";
}
<h2>Make View</h2>

<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Abrv)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Abrv)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</tbody>




But nothing is displaying on the site. Am I supposed to do something with the returned data? What am I doing wrong? I checked if the entities aren't getting the information from the database, they are.










share|improve this question















I'm trying to create a simple view (paging, sorting and filtering).
The method I have that does that looks something like this:



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, 
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
var data = _makeRepository.SelectListMake(index, count, orderLambda).AsQueryable();
return data;
}


You see it call another method from a repository, which looks the same



private readonly IQueryable<VehicleMakeEntity> _source;

public MakeRepository(ProjectDbContext context)
{
this.context = context;
_source = this.context.VehicleMake;
}

public IEnumerable<VehicleMakeEntity> SelectListMake(int index, int count,
Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _source.Skip(index * count).Take(count).OrderBy(orderLambda);
}


In my controller I call the method



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id));

return View(data);
}


And it returns some data I do not know how to work with as seen here





I also generated a View based on that controller method, a basic List View which you can see here



@model IEnumerable<Data.Entities.VehicleMakeEntity>
@using NonFactors.Mvc.Grid;
@{
ViewData["Title"] = "Make View";
}
<h2>Make View</h2>

<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Abrv)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Abrv)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</tbody>




But nothing is displaying on the site. Am I supposed to do something with the returned data? What am I doing wrong? I checked if the entities aren't getting the information from the database, they are.







c# asp.net-core dependency-injection entity-framework-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 6:23









Foo

1




1










asked Nov 20 at 5:04









TimmyNeutron

258




258








  • 2




    How many records are in your db (your code returns records 11 to 20). And as a side note, your .OrderBy() should be before .Skip()
    – user3559349
    Nov 20 at 5:34












  • So that was the problem. But why does it do that? I thought the second parameter limited how many records it pulls at a given time.
    – TimmyNeutron
    Nov 20 at 5:41












  • Because index=1 and .Skip(index * count) equates to .Skip(10) which means start at record number 11
    – user3559349
    Nov 20 at 5:52














  • 2




    How many records are in your db (your code returns records 11 to 20). And as a side note, your .OrderBy() should be before .Skip()
    – user3559349
    Nov 20 at 5:34












  • So that was the problem. But why does it do that? I thought the second parameter limited how many records it pulls at a given time.
    – TimmyNeutron
    Nov 20 at 5:41












  • Because index=1 and .Skip(index * count) equates to .Skip(10) which means start at record number 11
    – user3559349
    Nov 20 at 5:52








2




2




How many records are in your db (your code returns records 11 to 20). And as a side note, your .OrderBy() should be before .Skip()
– user3559349
Nov 20 at 5:34






How many records are in your db (your code returns records 11 to 20). And as a side note, your .OrderBy() should be before .Skip()
– user3559349
Nov 20 at 5:34














So that was the problem. But why does it do that? I thought the second parameter limited how many records it pulls at a given time.
– TimmyNeutron
Nov 20 at 5:41






So that was the problem. But why does it do that? I thought the second parameter limited how many records it pulls at a given time.
– TimmyNeutron
Nov 20 at 5:41














Because index=1 and .Skip(index * count) equates to .Skip(10) which means start at record number 11
– user3559349
Nov 20 at 5:52




Because index=1 and .Skip(index * count) equates to .Skip(10) which means start at record number 11
– user3559349
Nov 20 at 5:52












1 Answer
1






active

oldest

votes


















0














Can you check with below code.



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id)).ToList();

return View(data);
}


Also try to remove AsQueryable()



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _makeRepository.SelectListMake(index, count, orderLambda);
}





share|improve this answer





















  • I just did, it returns data Count = 0 now. It cannot be 0 as I foreached all the entities and they always return with the database value.
    – TimmyNeutron
    Nov 20 at 5:19










  • Ok, First check in repository with list. Getting any data from database. public List<VehicleMakeEntity> SelectListMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda) { var VehicleMakeEntity = _source.Skip(index * count).Take(count).OrderBy(orderLambda).ToList(); return VehicleMakeEntity; }
    – A.M. Patel
    Nov 20 at 5:33












  • Check VehicleMakeEntity varible any list return or not.
    – A.M. Patel
    Nov 20 at 5:36











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386530%2fhow-to-work-with-data-that-gets-returned-by-an-ienumerable-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









0














Can you check with below code.



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id)).ToList();

return View(data);
}


Also try to remove AsQueryable()



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _makeRepository.SelectListMake(index, count, orderLambda);
}





share|improve this answer





















  • I just did, it returns data Count = 0 now. It cannot be 0 as I foreached all the entities and they always return with the database value.
    – TimmyNeutron
    Nov 20 at 5:19










  • Ok, First check in repository with list. Getting any data from database. public List<VehicleMakeEntity> SelectListMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda) { var VehicleMakeEntity = _source.Skip(index * count).Take(count).OrderBy(orderLambda).ToList(); return VehicleMakeEntity; }
    – A.M. Patel
    Nov 20 at 5:33












  • Check VehicleMakeEntity varible any list return or not.
    – A.M. Patel
    Nov 20 at 5:36
















0














Can you check with below code.



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id)).ToList();

return View(data);
}


Also try to remove AsQueryable()



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _makeRepository.SelectListMake(index, count, orderLambda);
}





share|improve this answer





















  • I just did, it returns data Count = 0 now. It cannot be 0 as I foreached all the entities and they always return with the database value.
    – TimmyNeutron
    Nov 20 at 5:19










  • Ok, First check in repository with list. Getting any data from database. public List<VehicleMakeEntity> SelectListMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda) { var VehicleMakeEntity = _source.Skip(index * count).Take(count).OrderBy(orderLambda).ToList(); return VehicleMakeEntity; }
    – A.M. Patel
    Nov 20 at 5:33












  • Check VehicleMakeEntity varible any list return or not.
    – A.M. Patel
    Nov 20 at 5:36














0












0








0






Can you check with below code.



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id)).ToList();

return View(data);
}


Also try to remove AsQueryable()



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _makeRepository.SelectListMake(index, count, orderLambda);
}





share|improve this answer












Can you check with below code.



public IActionResult Make()
{
var data = _vehicleService.GetMake(1, 10, (p => p.Id)).ToList();

return View(data);
}


Also try to remove AsQueryable()



public IEnumerable<VehicleMakeEntity> GetMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda)
{
return _makeRepository.SelectListMake(index, count, orderLambda);
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 5:13









A.M. Patel

628




628












  • I just did, it returns data Count = 0 now. It cannot be 0 as I foreached all the entities and they always return with the database value.
    – TimmyNeutron
    Nov 20 at 5:19










  • Ok, First check in repository with list. Getting any data from database. public List<VehicleMakeEntity> SelectListMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda) { var VehicleMakeEntity = _source.Skip(index * count).Take(count).OrderBy(orderLambda).ToList(); return VehicleMakeEntity; }
    – A.M. Patel
    Nov 20 at 5:33












  • Check VehicleMakeEntity varible any list return or not.
    – A.M. Patel
    Nov 20 at 5:36


















  • I just did, it returns data Count = 0 now. It cannot be 0 as I foreached all the entities and they always return with the database value.
    – TimmyNeutron
    Nov 20 at 5:19










  • Ok, First check in repository with list. Getting any data from database. public List<VehicleMakeEntity> SelectListMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda) { var VehicleMakeEntity = _source.Skip(index * count).Take(count).OrderBy(orderLambda).ToList(); return VehicleMakeEntity; }
    – A.M. Patel
    Nov 20 at 5:33












  • Check VehicleMakeEntity varible any list return or not.
    – A.M. Patel
    Nov 20 at 5:36
















I just did, it returns data Count = 0 now. It cannot be 0 as I foreached all the entities and they always return with the database value.
– TimmyNeutron
Nov 20 at 5:19




I just did, it returns data Count = 0 now. It cannot be 0 as I foreached all the entities and they always return with the database value.
– TimmyNeutron
Nov 20 at 5:19












Ok, First check in repository with list. Getting any data from database. public List<VehicleMakeEntity> SelectListMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda) { var VehicleMakeEntity = _source.Skip(index * count).Take(count).OrderBy(orderLambda).ToList(); return VehicleMakeEntity; }
– A.M. Patel
Nov 20 at 5:33






Ok, First check in repository with list. Getting any data from database. public List<VehicleMakeEntity> SelectListMake(int index, int count, Expression<Func<VehicleMakeEntity, int>> orderLambda) { var VehicleMakeEntity = _source.Skip(index * count).Take(count).OrderBy(orderLambda).ToList(); return VehicleMakeEntity; }
– A.M. Patel
Nov 20 at 5:33














Check VehicleMakeEntity varible any list return or not.
– A.M. Patel
Nov 20 at 5:36




Check VehicleMakeEntity varible any list return or not.
– A.M. Patel
Nov 20 at 5:36


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386530%2fhow-to-work-with-data-that-gets-returned-by-an-ienumerable-method%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?