【发布时间】:2017-03-24 04:26:32
【问题描述】:
我在使用 OrmLite 填充 POCO 中的某些列时遇到了一些困难。我有三个名为 Dog、Bowl 和 DogBowl 的表。 DogBowl 是一个连接表,包含 Dog 和 Bowl 的 id。
Dogs
PK Id: int, not null
Breed: varchar(20), not null
Name: varchar(20), not null
Bowls
PK Id: int, not null
Type: varchar(20), not null
Color: varchar(20), not null
Dogs_Bowls
PK: DogId, not null
PK: BowlId, not null
这是我绘制的 POCO
public class Dog : IHasId<int>
{
[AutoIncrement]
public int Id { get; set; }
[Required]
public string Breed { get; set; }
[Required]
public string Name { get; set; }
}
public class Bowl : IHasId<int>
{
[AutoIncrement]
public int Id { get; set; }
[Required]
public string Type { get; set; }
[Required]
public string Color { get; set; }
}
public class DogBowl
{
[Required]
public int DogId { get; set; }
[Required]
public int BowlId { get; set; }
[Ignore]
public string DogName { get;set; }
[Ignore]
public string BowlColor { get;set; }
}
这是我正在运行的 c# 代码。
var dogBowl = db.Select<DogBowl>(db
.From<Dog>()
.Join<Dog, DogBowl>((d, db) => d.Id == db.DogId)
.Join<DogBowl, Bowl>((db, b) => db.BowlId == b.Id)
.Where<Dog>(d => d.Id == 5))
.ToList();
我想生成的 SQL 是这样的:
select
db.DogId,
db.BowlId,
d.Name AS DogName,
b.Color as BowlColor
from DogBowl db
join dog d on db.DogId = d.Id
join bowl b on db.BowlId = b.Id
where d.Id = 5
我的问题是代码执行后 DogBowl.DogName 和 DogBowl.BowlColor 属性为空。我正在使用标题为“在连接表中选择多个列”一节中https://github.com/ServiceStack/ServiceStack.OrmLite 上提供的说明,但它不起作用。如何填充 DogBowl.DogName 和 DogBowl.BowlColor 属性?
【问题讨论】:
标签: c# sql servicestack ormlite-servicestack