Estou tendo alguns problemas para obter uma lista do tipo "RhsTruck" por meio do Linq e fazer com que sejam exibidos.
RhsTruck só tem as propriedades Marca, Modelo, Serial etc ... RhsCustomer tem as propriedades CustomerName, CustomerAddress, etc ...
Continuo recebendo o erro "A sequência contém mais de um elemento". Alguma ideia? Estou abordando isso da maneira errada?
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();