[RESOLVED]How to fill Lists in ViewModel

 public
class
CustomerFeeViewModel

    {

public
int
CustomerId {
get;
set;
}

public
string
Comments {
get;
set;
}

public
IEnumerable<FeeModel>
Fees {
get;
set;
}

public
IEnumerable<ItemModel>
Items {
get;
set;
}

    }

I have trouble understanding how to fill the Fees and Items list in the ViewModel.

I’m using Linq to Entity. Do you have multiply queries? or can join in one query?

 

You can use include keyword in your linq query

e.g

ObjectQuery<SalesOrderHeader> query =
    context.SalesOrderHeaders.Include("Fees").Include("Items");

What does FeeModel and ItemModel contains and how they are related

So each Fee have a Item associated with it.

and each Customer have Fees against it.

var Custfeeitems = (from e in db.CustomerFeesPayments.Where(f => f.CustomerID = 1)
                           select new CustomerFeeViewModel
                           {

                               CustomerId = e.CustomerId,
                               Fees = e.FeeModel,
                               Comments = e.Comments
                           }.FirstOrDefault<CustomerFeeViewModel>()

alphabeatsco

So each Fee have a Item associated with it.

and each Customer have Fees against it.

I think ViewModel must be like following

    public class CustomerFeeViewModel
    {
        public int CustomerId { get; set; }

        public string Comments { get; set; }

        public IEnumerable<FeeModel> Fees { get; set; }
    }

And query, something like this

Leave a Reply