CSharp · Console
// @nuget: EntityFramework
// @nuget: EntityFramework.SqlServerCompact
// @nuget: Microsoft.SqlServer.Compact
// @nuget: Z.EntityFramework.Extensions
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()
{
// Custom configuration specific for .NET Fiddle
Z.EntityFramework.Extensions.EntityFrameworkManager.UseFiddleSqlCompact(System.Data.Entity.SqlServerCompact.SqlCeProviderServices.Instance, System.Data.SqlServerCe.SqlCeProviderFactory.Instance);
using (var context = new BookStore())
{
Book book = new Book(){Title = "Book"};
context.Books.Add(book);
context.SaveChanges();
var books = context.Books.ToList();
FiddleHelper.WriteTable(books);
}
}
public class BookStore : DbContext
{
public BookStore() : base(@"Data Source=ZZZ_Projects.sdf")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
public DbSet<Book> Books { get; set; }
}
public class Book
{
public int BookId { get; set; }
[MinLength(5)]
public string Title { get; set; }
}
}