你能给我任何从连接表查询和映射结果集的例子吗?我有以下代码:
DTO:
public class FormCatalogRecord
{
[Column("MFormId")]
public int Id { get; set; }
[Column("SGroupId")]
public int? GroupId { get; set; }
[Column("SGroupName")]
public string GroupName { get; set; }
[Column("STypeFormId")]
public int TypeId { get; set; }
[Column("MFormKod")]
public string Code { get; set; }
[Column("MFormName")]
public string Name { get; set; }
[Column("SFormPeriodName")]
public string Period { get; set; }
[Column("MFormDateStart")]
public DateTime? DateStarts { get; set; }
[Column("MFormDateEnd")]
public DateTime? DateEnds { get; set; }
[Column("MFormPublish")]
public DateTime? PublishDate { get; set; }
}
询问:
string formsQueryStr =
"FROM MForm " +
"INNER JOIN SFormPeriod ON MForm.SFormPeriodId = SFormPeriod.SFormPeriodId " +
"INNER JOIN SGroup ON MForm.SGroupId = SGroup.SGroupId " +
"ORDER BY MForm.SGroupId";
var test = db.Fetch<FormCatalogRecord>(formsQueryStr);
结果是异常:“不明确的列名'SGroupId'”。我试图改变属性:
[Column("MForm.SGroupId")]
public int? GroupId { get; set; }
现在我得到一个例外
列名“MForm.SGroupId”无效
令人惊讶的是,我在官方文档中没有找到任何示例。任何对 npoco 有效的帮助都会很有用。
更新
对于我的第一个案例,我正在生成以下 SQL:
SELECT
[MFormId] AS [Id], [SGroupId] AS [GroupId],
[SGroupName] AS [GroupName], [STypeFormId] AS [TypeId],
[MFormKod] AS [Code], [MFormName] AS [Name],
[SFormPeriodName] AS [Period], [MFormDateStart] AS [DateStarts],
[MFormDateEnd] AS [DateEnds], [MFormPublish] AS [PublishDate]
FROM
MForm
INNER JOIN
SFormPeriod ON MForm.SFormPeriodId = SFormPeriod.SFormPeriodId
INNER JOIN
SGroup ON MForm.SGroupId = SGroup.SGroupId
ORDER BY
MForm.SGroupId
我想我需要一些方法来添加“MForm”。在“[SGroupId] AS [GroupId]”之前。如果列属性可以支持类似 [Column("TableName.ColumnName")] 的语法,那就太好了