Nie mogę uzyskać kodu EF najpierw do pracy z SQL Server 2008 R2. Otrzymuję błąd "Niepoprawna nazwa obiektu" dbo.Movies "."Kod EF Najpierw CTP 5 i SQL SErver 2008 R2
Nie tworzy ona automatycznie tabeli.
Moje ciąg połączenia:
<add name="MovieDBContext" connectionString="Server=(local); Database=Movies; Trusted_Connection=true; Integrated Security=True" providerName="System.Data.SqlClient" />
Mój model i kontekst klasa:
public class Movie
{
public int ID { get; set; }
[Required(ErrorMessage = "Title is required")]
public string Title { get; set; }
[Required(ErrorMessage = "Date is required")]
public DateTime ReleaseDate { get; set; }
[Required(ErrorMessage = "Genre must be specified")]
public string Genre { get; set; }
[Required(ErrorMessage = "Price Required")]
[Range(1, 100, ErrorMessage = "Price must be between $1 and $100")]
public decimal Price { get; set; }
[StringLength(5)]
public string Rating { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Movie>().Property(p => p.Price).HasPrecision(18, 2);
}
}
Każda pomoc będzie mile widziane.
To nie było tak w mojej metodzie Application_Start, ale wydawało się, że nie działa. – Cliffboss
Sprawdź, czy tabela już istnieje i jeśli już istnieje, upewnij się, że nazwy tabel są zgodne. (Lub usuń tabelę i pozwól EF ją zbudować dla ciebie) w przeciwnym razie czegoś nam brakuje, jak powyższa metoda, gdy zostanie wywołana w Application_Start, zadziała. – Buildstarted
Wróciłem i zredagowałem dużo tutoriala, który zrobiłem + wykonałem to, co sugerowałeś i teraz działa. Pozdrawiam. – Cliffboss