Witam
Zacząłem tutorial dla EF Codefirst i mam problem z przykładowym pierwszym kodem, dla kompilatora brakuje namespace'a dla typu Context, może ktoś powiedzieć co poszło nie tak z instalacją czy wyborem namespace'ów?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
namespace EF_CodeFirst_tutorial
{
public class Program
{
static void Main(string[] args)
{
using (var ctx = new Context())
{
Student stud = new Student() { StudentName = "New Student" };
ctx.Students.Add(stud);
ctx.SaveChanges();
}
}
}
public class Student
{
public Student()
{
}
public int StudentID { get; set; }
public string StudentName { get; set; }
public DateTime? DateOfBirth { get; set; }
public byte[] Photo { get; set; }
public decimal Height { get; set; }
public float Weight { get; set; }
public Standard Standard { get; set; }
}
public class Standard
{
public Standard()
{
}
public int StandardId { get; set; }
public string StandardName { get; set; }
public ICollection<Student> Students { get; set; }
}
public class SchoolContext : DbContext
{
public SchoolContext() : base()
{
}
public DbSet<Student> Students { get; set; }
public DbSet<Standard> Standards { get; set; }
}
}
Tutorial robie z :
http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx
EF do projektu instalowałem przez NuGet.
W reference projektu mam biblioteki dodane przez instalację EF:
- EntityFramework
- EntityFramework.SqlServer
- System.ComponentModel.DataAnnotations
PS. Całość oczywiście działa jeżeli zamiast typu Context dam SchoolContext ale zgaduje że Context to jakiś typ bardziej abstrakcyjny?