CSharp · Console
// @nuget: EntityFramework
using System;
using System.Data.Entity;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
public class Program
{
public static void Main()
{
using (var context = new BookStore())
{
Book book = new Book(){Title = "My Book Long Title"};
context.Books.Add(book);
context.SaveChanges();
var books = context.Books.ToList();
FiddleHelper.WriteTable(books);
}
}
public class BookStore : DbContext
{
public BookStore() : base(FiddleHelper.GetConnectionStringSqlServer())
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
public DbSet<Book> Books { get; set; }
}
public class Book
{
public int BookId { get; set; }
[MaxLength(12)]
public string Title { get; set; }
}
}