我正在尝试将LINQ查询的输出保存到通用列表中,该列表是包含get和set的类的类型,但是它向我显示了无法隐式转换的错误,我搜索了许多解决方案对它而言对我没有帮助。以下是LINQ查询和泛型类定义。
LINQ查询:
public function checkmodel($model, $product_id=0) {
if (!$model) {return false; }
$sql = "SELECT * FROM `".DB_PREFIX."product` WHERE model='".$this->db->escape($model)."' AND sku='" AND product_id<>'".(int)$product_id."'";
$query = $this->db->query($sql);
return $query->rows;
类:
var posts = from p in db.Posts join c in db.Comments
on p.Post_ID equals c.postID
into PostComments
select new { PostId = p.Post_ID, Post = p.Post1, cmtcount = PostComments.Count() }
我只是像posts.ToList();
那样进行转换答案 0 :(得分:0)
var posts = from p in db.Posts join c in db.Comments
on p.Post_ID equals c.postID
into PostComments
select new Class1
{
PostId = p.Post_ID,
Post = p.Post1,
cmtcount = PostComments.Count()
};