可以用这种方式填充我的文本框吗? 在选择“无法隐式转换类型system.Linq.Querable”
时收到错误基本上我正在尝试为数据库创建一个,然后使用此连接填充Web表单上的其余文本框。
非常感谢任何帮助或指示。
private void Loadorder()
{
using (tyrescannerdatabaseEntities dbcontext = new tyrescannerdatabaseEntities())
query = (from Orders in dbcontext.Orders
join customer in dbcontext.Customers on Orders.CustomerID equals customer.CustomerID
join link_orderproduct in dbcontext.Link_OrderProduct on Orders.OrderID equals link_orderproduct.OrderID
join product in dbcontext.Products on link_orderproduct.ProductID equals product.ProductID
join garage in dbcontext.Garages on link_orderproduct.GarageID equals garage.GarageID
where Orders.OrderID == orderId.Value
select new DataMode
{
OrderID = Orders.OrderID,
Name = customer.Name
};
private void SetControlsWithRecord()
{
txtOrderID.Text = query.OrderID.ToString();
txtCustomer.Text = query.Customer.Name.ToString();
}
class DataMode
{
public int OrderID { get; set; }
public string Name { get; set; }
public string ContactNo { get; set; }
public string Registration { get; set; }
public string Brand { get; set; }
public string TyreModel { get; set; }
public decimal Width { get; set; }
public string Profile { get; set; }
public string Diamete { get; set; }
public string Speed { get; set; }
public string FittingDate { get; set; }
public decimal ProductUnitSalePrice { get; set; }
public string ProductQuantity { get; set; }
public string TotalProductSaleCost { get; set; }
public string MOT { get; set; }
public string AirConRecharge { get; set; }
public string WheelTracking { get; set; }
public string MOTS { get; set; }
}
答案 0 :(得分:0)
query = (from Orders in dbcontext.Orders
join customer in dbcontext.Customers on Orders.CustomerID equals customer.CustomerID
join link_orderproduct in dbcontext.Link_OrderProduct on Orders.OrderID equals link_orderproduct.OrderID
join product in dbcontext.Products on link_orderproduct.ProductID equals product.ProductID
join garage in dbcontext.Garages on link_orderproduct.GarageID equals garage.GarageID
where Orders.OrderID == orderId.Value
select new DataMode
{
OrderID = Orders.OrderID,
Name = customer.Name
}).ToList();
在查询结尾处添加此ToList()
。并从此处删除
txtOrderID.Text = query.OrderID.ToString();
txtCustomer.Text = query.Customer.Name.ToString();