存在しない列を発明しているようですこのように:その行が実行されたときEntity Frameworkのは、私がidはユーザによって送信されているものと一致する呪文のリストを取得するには、データベースをチェックしています。ここ
public partial class Spell
{
public int Id { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; }
public string Description { get; set; }
[StringLength(50)]
public string Page { get; set; }
[StringLength(50)]
public string Range { get; set; }
[StringLength(50)]
public string Components { get; set; }
public bool? Ritual { get; set; }
[StringLength(50)]
public string Duration { get; set; }
public bool? Concentration { get; set; }
[StringLength(50)]
public string CastingTime { get; set; }
public int Level { get; set; }
[StringLength(50)]
public string School { get; set; }
[Required]
[StringLength(100)]
public string Classes { get; set; }
[StringLength(100)]
public string Archetype { get; set; }
[StringLength(50)]
public string Domains { get; set; }
[StringLength(50)]
public string Oaths { get; set; }
[StringLength(50)]
public string Circles { get; set; }
}
しかし、私はspellbook_id
が列ではないというエラーが発生します。
私は実行のクエリを確認し、これはそれである:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent1].[Description] AS [Description],
[Extent1].[Page] AS [Page],
[Extent1].[Range] AS [Range],
[Extent1].[Components] AS [Components],
[Extent1].[Ritual] AS [Ritual],
[Extent1].[Duration] AS [Duration],
[Extent1].[Concentration] AS [Concentration],
[Extent1].[CastingTime] AS [CastingTime],
[Extent1].[Level] AS [Level],
[Extent1].[School] AS [School],
[Extent1].[Classes] AS [Classes],
[Extent1].[Archetype] AS [Archetype],
[Extent1].[Domains] AS [Domains],
[Extent1].[Oaths] AS [Oaths],
[Extent1].[Circles] AS [Circles],
[Extent1].[Spellbook_Id] AS [Spellbook_Id]
FROM [dbo].[Spells] AS [Extent1]
あなたが見ることができるように、何とかEFはテーブルからSpellbook_Id
を要求しているが、それは存在しません。それがどこにあるのかは分かりません。私はクラスを持っていますが、id、userid、およびList<Spell>
がありますが、実行しようとしているクエリは魔法書を全く参照すべきではなく、dbo.Spellsには外部キー制約がありません
EDIT:
public class Spellbook
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string UserId { get; set; }
public List<Spell> Spells { get; set; }
}
要求ごとにいくつかのより多くのコードを追加し、ここに私の状況です:
public partial class SpellbookAPIContext : DbContext
{
public SpellbookAPIContext() : base("name=SpellbookAPIContext")
{
}
public virtual DbSet<Spell> Spells { get; set; }
public virtual DbSet<Spellbook> Spellbooks { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Spell>()
.Property(e => e.Name)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Description)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Page)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Range)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Components)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Duration)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.CastingTime)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.School)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Classes)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Archetype)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Domains)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Oaths)
.IsUnicode(false);
modelBuilder.Entity<Spell>()
.Property(e => e.Circles)
.IsUnicode(false);
modelBuilder.Entity<Spellbook>()
.Property(e => e.Id)
.IsRequired();
modelBuilder.Entity<Spellbook>()
.Property(e => e.Name)
.IsRequired();
modelBuilder.Entity<Spellbook>()
.Property(e => e.UserId)
.IsRequired();
}
}
マッピングクラスを使用していますか?また、Spellbookクラスで参照したListはSpellのListですか? – abrown
私はそれを打ちましたが、私はバックティックを使わなかったので消えたと思います。私はそれを更新させてください。呪文ブックにはICollectionタイプのナビゲーションプロパティがあるので、魔法クラスをまだ使用していないので、呪文ブックを使用していません。 –
呪文はどの呪文に属しているかを覚えておくために外部呪文を必要とします。 EFはFKを見つけられなかったので、関係を確立する必要があり、それを発明しました。 – DevilSuichiro