當我嘗試轉換查詢時出現錯誤。這是查詢的代碼:鑄造變量時出錯
var query = (from article in db.V_CLIENT_PRIX
where article.CLIENT == Current_Client_Id
select new
{
ID = article.ID,
ARTICLE = article.Article,
REFERENCE = article.Reference,
REMISE = article.Remise,
PRIXVHT = article.PrixVHT,
CLIENT = article.CLIENT,
}
);
我投它是這樣的:
ConventionList articlelistconvention = new ConventionList();
articlelistconvention = (ConventionList)query;
這是我model:ConventionList
public class Commandelist
{
public string ARTICLE { get; set; }
public string CIN { get; set; }
public decimal STOCK { get; set; }
public string REFERENCE { get; set; }
public decimal PRIXVHT { get; set; }
public string IMAGE { get; set; }
public double QUANTITE { get; set; }
}
有人可以幫我解決它的代碼?
如果他們沒有任何關係,你不能投一個對象 – Imad
約定列表或Commandelist?這種投射不會奏效,但您可以實例化一個Commandelist的新實例並映射匹配的屬性 – LDJ