Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here's the C# classes that define the tables which Entity Framework will build
- Below these is the SQL code used to create the tables including the relationships with FK contraints
- public class BaseEntity
- {
- public int Id { get; set; }
- public bool Deleted { get; set; }
- }
- public class Store : BaseEntity
- {
- public POSProvider POSProvider { get; set; } // this and POSProviderId link the company that developed the store's POS
- public int POSProviderId { get; set; }
- public string StoreName { get; set; }
- public string Address { get; set; }
- public string ContactPerson { get; set; }
- public string ContactNumber { get; set; }
- public string EmailAddress { get; set; }
- public int Tellers { get; set; }
- public DateTime DateRegistered { get; set; }
- }
- public class Receipt : BaseEntity
- {
- public Store Store { get; set; }
- public int StoreId { get; set; }
- public User User { get; set; }
- public int? UserId { get; set; }
- public string ReceiptNumber { get; set; }
- public decimal ReceiptValue { get; set; }
- public DateTime ReceiptDate { get; set; }
- public decimal Cashback { get; set; }
- public DateTime ValidUntil { get; set; }
- public bool Calculated { get; set; }
- public bool Redeemed { get; set; }
- }
- SQL
- CREATE TABLE [dbo].[Stores](
- [Id] [int] IDENTITY(1,1) NOT NULL,
- [POSProviderId] [int] NOT NULL,
- [StoreName] [nvarchar](max) NULL,
- [Address] [nvarchar](max) NULL,
- [ContactPerson] [nvarchar](max) NULL,
- [ContactNumber] [nvarchar](max) NULL,
- [EmailAddress] [nvarchar](max) NULL,
- [Tellers] [int] NOT NULL,
- [DateRegistered] [datetime] NOT NULL,
- [Deleted] [bit] NOT NULL,
- CONSTRAINT [PK_dbo.Stores] PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
- GO
- ALTER TABLE [dbo].[Stores] WITH CHECK ADD CONSTRAINT [FK_dbo.Stores_dbo.POSProviders_POSProviderId] FOREIGN KEY([POSProviderId])
- REFERENCES [dbo].[POSProviders] ([Id])
- ON DELETE CASCADE
- GO
- ALTER TABLE [dbo].[Stores] CHECK CONSTRAINT [FK_dbo.Stores_dbo.POSProviders_POSProviderId]
- GO
- CREATE TABLE [dbo].[Receipts](
- [Id] [int] IDENTITY(1,1) NOT NULL,
- [StoreId] [int] NOT NULL,
- [UserId] [int] NULL,
- [ReceiptNumber] [nvarchar](max) NULL,
- [ReceiptValue] [decimal](18, 2) NOT NULL,
- [ReceiptDate] [datetime] NOT NULL,
- [Cashback] [decimal](18, 2) NOT NULL,
- [ValidUntil] [datetime] NOT NULL,
- [Calculated] [bit] NOT NULL,
- [Redeemed] [bit] NOT NULL,
- [Deleted] [bit] NOT NULL,
- [Invoice_Id] [int] NULL,
- CONSTRAINT [PK_dbo.Receipts] PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
- GO
- ALTER TABLE [dbo].[Receipts] WITH CHECK ADD CONSTRAINT [FK_dbo.Receipts_dbo.Stores_StoreId] FOREIGN KEY([StoreId])
- REFERENCES [dbo].[Stores] ([Id])
- ON DELETE CASCADE
- GO
- ALTER TABLE [dbo].[Receipts] CHECK CONSTRAINT [FK_dbo.Receipts_dbo.Stores_StoreId]
- GO
- ALTER TABLE [dbo].[Receipts] WITH CHECK ADD CONSTRAINT [FK_dbo.Receipts_dbo.Users_UserId] FOREIGN KEY([UserId])
- REFERENCES [dbo].[Users] ([Id])
- GO
- ALTER TABLE [dbo].[Receipts] CHECK CONSTRAINT [FK_dbo.Receipts_dbo.Users_UserId]
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement