EntityFramework 学习: Console中初见
生活随笔
收集整理的這篇文章主要介紹了
EntityFramework 学习: Console中初见
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
using System;
using System.Collections.Generic;
using System.Data.Entity;//在NuGet中獲取后,手動(dòng)引用之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();}}//實(shí)體類(lèi)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; }}//實(shí)體類(lèi)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; }}
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/chengdexy/p/5653863.html
總結(jié)
以上是生活随笔為你收集整理的EntityFramework 学习: Console中初见的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 银行卡后六位代表什么意思
- 下一篇: awk多分隔符功能及wc命令案列及企业级