使用 SELECT JOIN 的 BLToolkit 复杂映射
尝试在我的项目中使用 BLToolkit 映射器。有件事我真的不知道如何解决,问题是我有 2 个类 Content 和 Comment。
[MapField("CommentItemId","CommentContent.ContentId")]
public class Comment
{
[MapField("Comment.CommentId")]
public int CommentId;
[Relation(typeof(Content))]
public Content CommentContent;
}
public class Content
{
[MapField("ContentId"),PrimaryKey]
public int ContentId;
public IList<Comment> Comments = new List<Comment>();
}
好吧,看起来就像大家在 BLToolkit.net 上看到的简单的复杂映射示例一样。 但是,我正在尝试使用 SELECT JOIN 查询。这是我的查询。
MapResultSet[] sets = new MapResultSet[2];
sets[0] = new MapResultSet(typeof(Content));
sets[1] = new MapResultSet(typeof(Comment));
command = String.Format(@"SELECT con.ContentId,com.CommentId,com.CommentItemId
FROM Content as con,Comments as com
WHERE (con.ContentId = com.CommentItemId AND con.ContentId {0})", itemid, type);
此查询返回正确的数据(使用 ExecuteReader 检查)。但是在 MapResultSets 中只有 Content 数据,没有 Comment 数据...如果我将交换 Content 和 Comment 集...我将只得到 Comment 数据,而没有 Content 数据...我现在甚至不关心关系,我只是想向 BLToolkit 解释一下,1 行中有 2 个类的数据。
Trying to use BLToolkit mapper in my project. There is a thing that I really don't know how to solve , the deal is that I have 2 classes Content and Comment.
[MapField("CommentItemId","CommentContent.ContentId")]
public class Comment
{
[MapField("Comment.CommentId")]
public int CommentId;
[Relation(typeof(Content))]
public Content CommentContent;
}
public class Content
{
[MapField("ContentId"),PrimaryKey]
public int ContentId;
public IList<Comment> Comments = new List<Comment>();
}
Well , looks as simple Complex Mapping as example that everybody saw on BLToolkit.net .
But , I'm trying to use SELECT JOIN query. This is my query.
MapResultSet[] sets = new MapResultSet[2];
sets[0] = new MapResultSet(typeof(Content));
sets[1] = new MapResultSet(typeof(Comment));
command = String.Format(@"SELECT con.ContentId,com.CommentId,com.CommentItemId
FROM Content as con,Comments as com
WHERE (con.ContentId = com.CommentItemId AND con.ContentId {0})", itemid, type);
This query returns correct data ( checked with ExecuteReader ). But in MapResultSets there is only Content data , no Comment data ... If i will interchange Content and Comment sets ... I will get only Comment data , and no Content data ... I don't even care about realtions right now , i just want to explain to BLToolkit , that there is data of 2 classes in 1 row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论