Guest User

Untitled

a guest
Jul 13th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. DbDatabase.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. namespace Proto
  9. {
  10. using System.Data;
  11. using System.Data.Entity;
  12. using System.Data.Entity.Database;
  13. using System.Data.SqlServerCe;
  14. using System.ComponentModel.DataAnnotations;
  15.  
  16. class Program
  17. {
  18. static void Main(string[] args)
  19. {
  20. DbDatabase.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
  21. DbDatabase.SetInitializer(new DropCreateDatabaseIfModelChanges<ProtoCatalog>());
  22.  
  23. using (var db = new ProtoCatalog())
  24. {
  25. var user = new User
  26. {
  27. Name = "bob",
  28. Password = "123",
  29. Creation = DateTime.Now,
  30. PrimaryEmailAddress = "bob@example.com"
  31. };
  32.  
  33. db.Users.Add(user);
  34.  
  35. db.SaveChanges();
  36.  
  37. Console.ReadKey();
  38. }
  39. }
  40. }
  41.  
  42. public class ProtoCatalog : DbContext
  43. {
  44. public DbSet<User> Users { get; set; }
  45. }
  46.  
  47. public class User
  48. {
  49. [Key, StringLength(50)]
  50. public string Name { get; set; }
  51.  
  52. [Required, StringLength(100)]
  53. public string Password { get; set; }
  54.  
  55. [Required, StringLength(320)]
  56. public string PrimaryEmailAddress { get; set; }
  57.  
  58. [StringLength(320)]
  59. public string SecondaryEmailAddress { get; set; }
  60.  
  61. [Required]
  62. public DateTime Creation { get; set; }
  63.  
  64. public bool Active { get; set; }
  65. }
  66. }
  67.  
  68. install-package EFCodeFirst.SqlServerCompact
  69. install-package EFCodeFirst.Sample
Add Comment
Please, Sign In to add comment