EFはこの1つのテーブルを作成していないようです
NotesModels.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Web.Security;
namespace note.DO.Models
{
public class NotesContext : DbContext
{
public NotesContext()
: base("DefaultConnection")
{
}
public DbSet<UserNotes> Notes { get; set; }
public DbSet<UserProfile> UserProfiles { get; set; }
}
[Table("UserNotes")]
public class UserNotes
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int NoteId { get; set; }
public virtual int UserId { get; set; }
[ForeignKey("UserId")]
public virtual UserProfile User { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime? Added { get; set; }
public DateTime? Edited { get; set; }
}
public class CreateNoteModel
{
[Display(Name = "Author")]
public UserProfile Author { get; set; }
[Required]
[DataType(DataType.Text)]
[Display(Name = "Title")]
public string Title { get; set; }
[Required]
[DataType(DataType.MultilineText)]
[Display(Name = "Content")]
public string Content { get; set; }
[DataType(DataType.DateTime)]
[Display(Name = "Added on")]
public DateTime? AddedOn { get; set; }
}
}
これらのクラスを使用してコントローラーを生成しました。ただし、メモを追加しようとすると、次の例外が発生します。
オブジェクト名 'dbo.UserNotes' が無効です。
...この行によってトリガーされます:
db.SaveChanges();
私が試したこと:
- スキーマを「dbo」に変更 ([Table("UserNotes", Schema:"dbo")]) を追加)
- Visual Studio からデータベース ファイル全体を手動で削除する
- 複数形を単数形に変えて元に戻す
- Entity Framework の再インストール
何か案は?おそらく、私がしていて気づいていない本当にばかげたことがありますか?
編集: UserProfile クラスとデータ コンテキスト:
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
}
(...)
(other models)