خرید بک لینک

سلام دوستان من میخواستم یک دیتا بیس از طریق Code first ایجاد کنم ..
اما نمیدونم مشکلم کجاست ؟؟! و چرا به اروو میخوردم ؟؟ من کانکشن استیرنگ هم ب صورت زیر تعریف کردم .. دوستان میتونن راهنمایی کنن؟؟
ویا یک نمونه میخواستم دیتا بیس از طریق Code first برام بزارین ..

<coectionStrings>        <add name="SchoolContext" coectionString="Data Source=.;Initial Catalog=SchoolContext;Integrated Security=True" providerName="System.Data.SqlClient" />
</coectionStrings>

static void Main(string[] args)
{
var ctx = new SchoolContext();

Student stud = new Student() { StudentName = "New Student" };

ctx.Students.Add(stud);
ctx.SaveChanges();

}

public class SchoolContext : DbContext
{
public SchoolContext(): base()
{

}
public DbSet<Student> Students { get; set; }
public DbSet<Standard> Standards { get; set; }
}

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 Teacher Teacher { 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 Teacher
{
public Teacher()
{

}
public int TeacherId { get; set; }
public string TeacherName { get; set; }
}


55.png

برچسب: نویسنده: محمد رضا جوادیان تاريخ: سه شنبه 5 مرداد 1395 ساعت: 23:07

صفحه بندی