考虑我在下面的LoyaltyCard
数据库DTO:
[Alias("customer_ids")]
[CompositeIndex("id_code", "id_number", Unique = true)]
public class LoyaltyCard
{
[Alias("customer_code")]
public int CustomerId { get; set; }
[Alias("id_code")]
public string LoyaltyCardCode { get; set; }
[Alias("id_number")]
public string LoyaltyCardNumber { get; set; }
[Alias("date_issued ")]
public DateTime? IssueDate { get; set; }
[Alias("linked_id")]
public bool LinkedId { get; set; }
[Alias("positive_id")]
public bool PositiveId { get; set; }
}
我有CustomerId
作为属性,因为我需要它包含在生成的SQL的WHERE
子句中,但我不希望在结果中也选择该列组。有没有办法将它包含在哪里但是从select中排除?
// I was hoping that result would not have a populated CustomerIds
var result = db.Select<LoyaltyCard>(id => id.LoyaltyCardCode == "PS" && id.CustomerId == customerCode);
我尝试添加[Ignore]
属性,但失败了SqlException: Invalid column name 'CustomerId'
。
答案 0 :(得分:2)
如果您不想填充整个POCO,则需要指定仅包含您想要选择的字段的自定义选择,例如:
var result = db.Select<LoyaltyCard>(db.From<LoyaltyCard>()
.Where(id => id.LoyaltyCardCode == "PS" && id.CustomerId == customerCode)
.Select(x => new {
x.LoyaltyCardCode,
x.LoyaltyCardNumber,
x.IssueDate,
x.LinkedId,
x.PositiveId
}));