EntityFramework 学习: Console中初见
生活随笔
收集整理的这篇文章主要介绍了
EntityFramework 学习: Console中初见
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
using System;
using System.Collections.Generic;
using System.Data.Entity;//在NuGet中获取后,手动引用之namespace EF_Test
{class Program{static void Main(string[] args){var d = DateTime.Now.Date.ToString("yyyyMM");var destination = new Destination{Country = "Indonesia",Description = "EcoTourism at its best in exquisite Bali",Name = "Bali"};using (var context = new EF_TestContext()){context.Destinations.Add(destination);context.SaveChanges();}Console.WriteLine("OK");Console.ReadLine();}}//实体类1 ===> 映射为表:Destinations中的记录public class Destination{public int DestinationId { get; set; }public string Name { get; set; }public string Country { get; set; }public string Description { get; set; }public byte[] Photo { get; set; }public List<Lodging> Lodgings { get; set; }}//实体类2 ===> 映射为表:Lodgings中的记录public class Lodging{public int LodgingId { get; set; }public string Name { get; set; }public string Owner { get; set; }public bool IsResort { get; set; }public Destination Destination { get; set; }}public class EF_TestContext : DbContext{//表Destinationspublic DbSet<Destination> Destinations { get; set; }//表Lodgingspublic DbSet<Lodging> Lodgings { get; set; }}
}
转载于:https://www.cnblogs.com/chengdexy/p/5653863.html
总结
以上是生活随笔为你收集整理的EntityFramework 学习: Console中初见的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 银行卡后六位代表什么意思
- 下一篇: awk多分隔符功能及wc命令案列及企业级