Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DbDatabase.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Proto
- {
- using System.Data;
- using System.Data.Entity;
- using System.Data.Entity.Database;
- using System.Data.SqlServerCe;
- using System.ComponentModel.DataAnnotations;
- class Program
- {
- static void Main(string[] args)
- {
- DbDatabase.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
- DbDatabase.SetInitializer(new DropCreateDatabaseIfModelChanges<ProtoCatalog>());
- using (var db = new ProtoCatalog())
- {
- var user = new User
- {
- Name = "bob",
- Password = "123",
- Creation = DateTime.Now,
- PrimaryEmailAddress = "bob@example.com"
- };
- db.Users.Add(user);
- db.SaveChanges();
- Console.ReadKey();
- }
- }
- }
- public class ProtoCatalog : DbContext
- {
- public DbSet<User> Users { get; set; }
- }
- public class User
- {
- [Key, StringLength(50)]
- public string Name { get; set; }
- [Required, StringLength(100)]
- public string Password { get; set; }
- [Required, StringLength(320)]
- public string PrimaryEmailAddress { get; set; }
- [StringLength(320)]
- public string SecondaryEmailAddress { get; set; }
- [Required]
- public DateTime Creation { get; set; }
- public bool Active { get; set; }
- }
- }
- install-package EFCodeFirst.SqlServerCompact
- install-package EFCodeFirst.Sample
Add Comment
Please, Sign In to add comment