-
Feb 9th, 2019, 06:58 PM
#1
Thread Starter
Lively Member
How to bind sales header model to collection of sales Footer
problem
How to bind sales header model to collection of sales Footer on SalesOrder controller using ASP.NET core 2.1?
I work on project have Sales Order form this form contain to :
salesHeader model
salesFooter model
so that i already have model Sales Header have navigation property to Sales Footer as following
SalesHeader Model
public int SalesOrderNo { get; set; }
public int SalesYear { get; set; }
public ICollection<SalesFooter> SalesFooters { get; set; }
SalesFooter Model
public int SalesOrderNo { get; set; }
public int Quantity { get; set; }
public int UnitPrice { get; set; }
How to get collection of sales footer on :
on Edit action of sales Order controller how to get collection of sales footer ?
on Edit view(get) sales Order controller how to get collection of sales footer ?
What I have tried:
Repository
public T GetById(int Id)
{
return dbSet.Find(Id);
}
public class SalesOrderController : Controller
{
private readonly IrepositoryTab<SalesHeader> _repositoryHeader;
public SalesOrderController(IrepositoryTab<SalesHeader> SalesHeader, IrepositoryTab<SalesFooter> SalesFooter)
{
this._repositoryHeader = SalesHeader;
this._repositoryFooter = SalesFooter;
}
//get
//Edit Action of sales Order Controller
public IActionResult Edit(int? id)
{
var SalesHeader = _repositoryHeader.GetById(id);
//How to bind with sales footer
return View();
}
-
Feb 9th, 2019, 07:50 PM
#2
Re: How to bind sales header model to collection of sales Footer
Reading unformatted code is rather unpleasant. Please format all code snippets appropriately. With 44 posts now, I would have expected that you'd have seen that done a number
Originally Posted by engbarbary
problem
How to bind sales header model to collection of sales Footer on SalesOrder controller using ASP.NET core 2.1?
I work on project have Sales Order form this form contain to :
salesHeader model
salesFooter model
so that i already have model Sales Header have navigation property to Sales Footer as following
SalesHeader Model
csharp Code:
public int SalesOrderNo { get; set; } public int SalesYear { get; set; } public ICollection<SalesFooter> SalesFooters { get; set; }
SalesFooter Model
csharp Code:
public int SalesOrderNo { get; set; } public int Quantity { get; set; } public int UnitPrice { get; set; }
How to get collection of sales footer on :
on Edit action of sales Order controller how to get collection of sales footer ?
on Edit view(get) sales Order controller how to get collection of sales footer ?
What I have tried:
Repository
csharp Code:
public T GetById(int Id) { return dbSet.Find(Id); } public class SalesOrderController : Controller { private readonly IrepositoryTab<SalesHeader> _repositoryHeader; public SalesOrderController(IrepositoryTab<SalesHeader> SalesHeader, IrepositoryTab<SalesFooter> SalesFooter) { this._repositoryHeader = SalesHeader; this._repositoryFooter = SalesFooter; } //get //Edit Action of sales Order Controller public IActionResult Edit(int? id) { var SalesHeader = _repositoryHeader.GetById(id); //How to bind with sales footer return View(); }
-
Feb 9th, 2019, 07:58 PM
#3
Re: How to bind sales header model to collection of sales Footer
As for your issue, you don't need to get the two separately. When you get the root entity from EF, you can use the Include method to specify related entities to retrieve as well. Here's an example from a current project I'm working on:
csharp Code:
var aspNetUser = await dbContext.AspNetUsers .Include(u => u.CreatedByUser) .Include(u => u.UpdatedByUser) .Include(u => u.RegistrationUser) .Include(u => u.AspNetUserRoles) .ThenInclude(ur => ur.Role) .AsNoTracking() .FirstOrDefaultAsync(u => u.Id == id);
That's using EF Core but, if you're using EF 6, it should be pretty similar. I'm not sure that EF6 has ThenInclude but you can just provide a navigation path in the Include method.
-
Feb 10th, 2019, 04:13 AM
#4
Thread Starter
Lively Member
Re: How to bind sales header model to collection of sales Footer
ok thank you for reply
and how to show list on view of edit
-
Feb 10th, 2019, 04:29 AM
#5
Thread Starter
Lively Member
Re: How to bind sales header model to collection of sales Footer
ok thank you for reply
and how to show list on view of edit
-
Feb 10th, 2019, 05:46 AM
#6
Re: How to bind sales header model to collection of sales Footer
The same way you display any other data. If you're displaying one record then you hard-code each field and if you are displaying a list of records then you use a loop. In this case you are doing both so you do both.
-
Feb 10th, 2019, 08:40 AM
#7
Thread Starter
Lively Member
Re: How to bind sales header model to collection of sales Footer
and from which place i will get data on list that I will loop on it
-
Feb 10th, 2019, 08:46 AM
#8
Re: How to bind sales header model to collection of sales Footer
Originally Posted by engbarbary
and from which place i will get data on list that I will loop on it
I don't understand how you can be asking me that. Did someone else write post #1 for you?
Originally Posted by engbarbary
so that i already have model Sales Header have navigation property to Sales Footer as following
SalesHeader Model
Code:
public int SalesOrderNo { get; set; }
public int SalesYear { get; set; }
public ICollection<SalesFooter> SalesFooters { get; set; }
What exactly do you think that is?
-
Feb 10th, 2019, 09:12 AM
#9
Thread Starter
Lively Member
Re: How to bind sales header model to collection of sales Footer
what i understand on first query get data of master details and after that how to get these data from query to list
this is myquestion
-
Feb 10th, 2019, 09:12 AM
#10
Thread Starter
Lively Member
Re: How to bind sales header model to collection of sales Footer
what i understand on first query get data of master details and after that how to get these data from query to list
this is my question
-
Feb 12th, 2019, 02:38 AM
#11
Thread Starter
Lively Member
Re: How to bind sales header model to collection of sales Footer
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|