Tengo algunos problemas para obtener una lista del tipo "RhsTruck" a través de Linq y hacer que se muestren.
RhsTruck solo tiene las propiedades Marca, Modelo, Serie, etc. RhsCustomer tiene propiedades CustomerName, CustomerAddress, etc.
Sigo recibiendo el error "La secuencia contiene más de un elemento". ¿Algunas ideas? ¿Me estoy acercando a esto de la manera incorrecta?
public RhsCustomer GetCustomer(string customerNumber)
{
using (RhsEbsDataContext context = new RhsEbsDataContext() )
{
RhsCustomer rc = (from x in context.custmasts
where x.kcustnum == customerNumber
select new RhsCustomer()
{
CustomerName = x.custname,
CustomerAddress = x.custadd + ", " + x.custcity
CustomerPhone = x.custphone,
CustomerFax = x.custfax
}).SingleOrDefault();
return rc;
}
}
public List<RhsTruck> GetEquipmentOwned(RhsCustomer cust)
{
using (RhsEbsDataContext context = new RhsEbsDataContext())
{
var trucks = (from m in context.mkpops
join c in context.custmasts
on m.kcustnum equals c.kcustnum
where m.kcustnum == cust.CustomerNumber
select new RhsTruck
{
Make = m.kmfg,
Model = m.kmodel,
Serial = m.kserialnum,
EquipID = m.kserialno1,
IsRental = false
}).ToList();
return trucks;
}
}
protected void Page_Load(object sender, EventArgs e)
{
string testCustNum = Page.Request.QueryString["custnum"].ToString();
RhsCustomerRepository rcrep = new RhsCustomerRepository();
RhsCustomer rc = rcrep.GetCustomer(testCustNum);
List<RhsTruck> trucks = rcrep.GetEquipmentOwned(rc);
// I want to display the List into a Gridview w/auto-generated columns
GridViewTrucks.DataSource = trucks;
GridViewTrucks.DataBind();
}
.Take(1).SingleOrDefault();