Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. Here's the C# classes that define the tables which Entity Framework will build
  2. Below these is the SQL code used to create the tables including the relationships with FK contraints
  3.  
  4. public class BaseEntity
  5. {
  6. public int Id { get; set; }
  7. public bool Deleted { get; set; }
  8. }
  9.  
  10. public class Store : BaseEntity
  11. {
  12. public POSProvider POSProvider { get; set; } // this and POSProviderId link the company that developed the store's POS
  13. public int POSProviderId { get; set; }
  14. public string StoreName { get; set; }
  15. public string Address { get; set; }
  16. public string ContactPerson { get; set; }
  17. public string ContactNumber { get; set; }
  18. public string EmailAddress { get; set; }
  19. public int Tellers { get; set; }
  20. public DateTime DateRegistered { get; set; }
  21. }
  22.  
  23. public class Receipt : BaseEntity
  24. {
  25. public Store Store { get; set; }
  26. public int StoreId { get; set; }
  27. public User User { get; set; }
  28. public int? UserId { get; set; }
  29. public string ReceiptNumber { get; set; }
  30. public decimal ReceiptValue { get; set; }
  31. public DateTime ReceiptDate { get; set; }
  32. public decimal Cashback { get; set; }
  33. public DateTime ValidUntil { get; set; }
  34. public bool Calculated { get; set; }
  35. public bool Redeemed { get; set; }
  36. }
  37.  
  38. SQL
  39.  
  40. CREATE TABLE [dbo].[Stores](
  41. [Id] [int] IDENTITY(1,1) NOT NULL,
  42. [POSProviderId] [int] NOT NULL,
  43. [StoreName] [nvarchar](max) NULL,
  44. [Address] [nvarchar](max) NULL,
  45. [ContactPerson] [nvarchar](max) NULL,
  46. [ContactNumber] [nvarchar](max) NULL,
  47. [EmailAddress] [nvarchar](max) NULL,
  48. [Tellers] [int] NOT NULL,
  49. [DateRegistered] [datetime] NOT NULL,
  50. [Deleted] [bit] NOT NULL,
  51. CONSTRAINT [PK_dbo.Stores] PRIMARY KEY CLUSTERED
  52. (
  53. [Id] ASC
  54. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  55. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  56.  
  57. GO
  58.  
  59. ALTER TABLE [dbo].[Stores] WITH CHECK ADD CONSTRAINT [FK_dbo.Stores_dbo.POSProviders_POSProviderId] FOREIGN KEY([POSProviderId])
  60. REFERENCES [dbo].[POSProviders] ([Id])
  61. ON DELETE CASCADE
  62. GO
  63.  
  64. ALTER TABLE [dbo].[Stores] CHECK CONSTRAINT [FK_dbo.Stores_dbo.POSProviders_POSProviderId]
  65. GO
  66.  
  67. CREATE TABLE [dbo].[Receipts](
  68. [Id] [int] IDENTITY(1,1) NOT NULL,
  69. [StoreId] [int] NOT NULL,
  70. [UserId] [int] NULL,
  71. [ReceiptNumber] [nvarchar](max) NULL,
  72. [ReceiptValue] [decimal](18, 2) NOT NULL,
  73. [ReceiptDate] [datetime] NOT NULL,
  74. [Cashback] [decimal](18, 2) NOT NULL,
  75. [ValidUntil] [datetime] NOT NULL,
  76. [Calculated] [bit] NOT NULL,
  77. [Redeemed] [bit] NOT NULL,
  78. [Deleted] [bit] NOT NULL,
  79. [Invoice_Id] [int] NULL,
  80. CONSTRAINT [PK_dbo.Receipts] PRIMARY KEY CLUSTERED
  81. (
  82. [Id] ASC
  83. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  84. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  85.  
  86. GO
  87.  
  88. ALTER TABLE [dbo].[Receipts] WITH CHECK ADD CONSTRAINT [FK_dbo.Receipts_dbo.Stores_StoreId] FOREIGN KEY([StoreId])
  89. REFERENCES [dbo].[Stores] ([Id])
  90. ON DELETE CASCADE
  91. GO
  92.  
  93. ALTER TABLE [dbo].[Receipts] CHECK CONSTRAINT [FK_dbo.Receipts_dbo.Stores_StoreId]
  94. GO
  95.  
  96. ALTER TABLE [dbo].[Receipts] WITH CHECK ADD CONSTRAINT [FK_dbo.Receipts_dbo.Users_UserId] FOREIGN KEY([UserId])
  97. REFERENCES [dbo].[Users] ([Id])
  98. GO
  99.  
  100. ALTER TABLE [dbo].[Receipts] CHECK CONSTRAINT [FK_dbo.Receipts_dbo.Users_UserId]
  101. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement