标签:mode get adl pen string packages soft logs bsp
To keep things simple we’re going to build a basic console application that uses Code First to perform data access.
public class Department { [Key] public int DepartmentID { get; set; } public int CourseID { get; set; } [ForeignKey("CourseID")] public Course Course { get; set; } public string Name { get; set; } }
public class QxunDbContext : DbContext { public QxunDbContext() : base("server=localhost;uid=sa;pwd=6665508a;database=Qxun;") { } public DbSet<Department> Departments { get; set; } }
using (var db = new BloggingContext()) { // Create and save a new Blog Console.Write("Enter a name for a new Blog: "); var name = Console.ReadLine(); var blog = new Blog { Name = name }; db.Blogs.Add(blog); db.SaveChanges(); // Display all Blogs from the database var query = from b in db.Blogs orderby b.Name select b; Console.WriteLine("All blogs in the database:"); foreach (var item in query) { Console.WriteLine(item.Name); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
Entity Framework Code First to a New Database
标签:mode get adl pen string packages soft logs bsp
原文地址:http://www.cnblogs.com/liandy0906/p/7135933.html