我具有以下模型结构:
技能意图(SkillId的外键)技巧(IntentId的外键)插槽(UtteranceId的外键)
意图模型
public class Intent
{
[Key]
public int Id { get; set; }
[ForeignKey("Skill")]
public int? SkillId { get; set; }
public string Description { get; set; }
public virtual Skill Skill { get; set; }
public virtual List<Utterance> Utterances { get; set; }
}
话语模型
public class Utterance
{
[Key]
public int Id { get; set; }
[ForeignKey("Intent")]
public int IntentId { get; set; }
public string Utterancetext { get; set; }
public virtual Intent Intent { get; set; }
public virtual List<Slot> Slots { get; set; }
}
插槽型号
public class Slot
{
[Key]
public int Id { get; set; }
[ForeignKey("Utterance")]
public int UtteranceId { get; set; }
public string SlotValue { get; set; }
public SlotDataTypes SlotDataType { get; set; }
public virtual Utterance Utterance { get; set; }
}
实体框架流利的API
modelBuilder.Entity<Intent>()
.HasOptional(i => i.Skill)
.WithMany(sk => sk.Intents)
.HasForeignKey(i => i.SkillId);
modelBuilder.Entity<Utterance>()
.HasRequired(x => x.Intent)
.WithMany(x => x.Utterances)
.HasForeignKey(x => x.IntentId);
modelBuilder.Entity<Slot>()
.HasRequired(x => x.Utterance)
.WithMany(x => x.Slots)
.HasForeignKey(x => x.UtteranceId);
在我的数据访问服务中,我有一种方法应获取“意图”>“话语”>“插槽”。
var intents = ctx.Intents.Include(x => x.Utterances).Include("Utterances.Slots").ToList(); //<-- utterances are populated, slots count is 0
var utterances = ctx.Utterances.Include(x => x.Slots).ToList(); // utterances are populated, slots are populated
var slots = ctx.Slots.ToList(); // slots are populated
return intents;
我需要的第一个电话是让我了解所有意图,它们的相关发音以及与发音相关的位置。尽管数据库中肯定有插槽,但说话总是在填充,但插槽始终为零,第二次调用证明了这一点,因为如果我只是直奔Utterances并包含Slot,我会重新获得插槽。
从Intent导航一直到Slots,我在哪里出错?
相关分类