QLiberaceContext.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.EntityFrameworkCore.Metadata;
  5. namespace Workbench.Entity
  6. {
  7. public partial class QLiberaceContext : DbContext
  8. {
  9. public QLiberaceContext()
  10. {
  11. }
  12. public QLiberaceContext(DbContextOptions<QLiberaceContext> options)
  13. : base(options)
  14. {
  15. }
  16. public virtual DbSet<Contact> Contacts { get; set; } = null!;
  17. public virtual DbSet<Country> Countries { get; set; } = null!;
  18. public virtual DbSet<Currency> Currencies { get; set; } = null!;
  19. public virtual DbSet<Customer> Customers { get; set; } = null!;
  20. public virtual DbSet<CustomerUser> CustomerUsers { get; set; } = null!;
  21. public virtual DbSet<Setting> Settings { get; set; } = null!;
  22. public virtual DbSet<Tenant> Tenants { get; set; } = null!;
  23. public virtual DbSet<TenantCountry> TenantCountries { get; set; } = null!;
  24. public virtual DbSet<TenantCurrency> TenantCurrencies { get; set; } = null!;
  25. public virtual DbSet<TenantUser> TenantUsers { get; set; } = null!;
  26. public virtual DbSet<User> Users { get; set; } = null!;
  27. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  28. {
  29. if (!optionsBuilder.IsConfigured)
  30. {
  31. #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
  32. optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=QLiberace;Trusted_Connection=True;");
  33. }
  34. }
  35. protected override void OnModelCreating(ModelBuilder modelBuilder)
  36. {
  37. modelBuilder.Entity<Contact>(entity =>
  38. {
  39. entity.ToTable("Contact", "Customer");
  40. entity.Property(e => e.Id).HasComment("Contact primary key");
  41. entity.Property(e => e.Address)
  42. .HasMaxLength(100)
  43. .HasComment("Main address value. If phone, email, sms stores email address or telephone number.");
  44. entity.Property(e => e.Address1)
  45. .HasMaxLength(100)
  46. .HasComment("Secondary address value.");
  47. entity.Property(e => e.Caption)
  48. .HasMaxLength(100)
  49. .HasComment("Contact heading caption.");
  50. entity.Property(e => e.City)
  51. .HasMaxLength(50)
  52. .HasComment("Contact city.");
  53. entity.Property(e => e.CountryCode)
  54. .HasMaxLength(5)
  55. .HasComment("Contact country code.");
  56. entity.Property(e => e.Created)
  57. .HasColumnType("datetime")
  58. .HasDefaultValueSql("(getdate())")
  59. .HasComment("Record created timestamp");
  60. entity.Property(e => e.CustomerId).HasComment("Reference to customer that contact belongs");
  61. entity.Property(e => e.IsPreffered).HasComment("Flag if Contact is preffered.");
  62. entity.Property(e => e.Modified)
  63. .HasColumnType("datetime")
  64. .HasComment("Record modified timestamp");
  65. entity.Property(e => e.Modifier)
  66. .HasMaxLength(100)
  67. .HasComment("Record modifier signature");
  68. entity.Property(e => e.TenantCode)
  69. .HasMaxLength(20)
  70. .HasComment("Reference to tenant code that contact belongs");
  71. entity.Property(e => e.Type).HasComment("Contact type (0-Email, 1-Address, 2-Phone, 3-SMS)");
  72. entity.Property(e => e.Zip)
  73. .HasMaxLength(20)
  74. .HasColumnName("ZIP")
  75. .HasComment("Contact ZIP code.");
  76. entity.HasOne(d => d.Customer)
  77. .WithMany(p => p.Contacts)
  78. .HasForeignKey(d => d.CustomerId)
  79. .OnDelete(DeleteBehavior.ClientSetNull)
  80. .HasConstraintName("REL_CONTACT_CUSTOMER_ID");
  81. });
  82. modelBuilder.Entity<Country>(entity =>
  83. {
  84. entity.ToTable("Country", "base");
  85. entity.HasIndex(e => e.Code, "IDX_COUNTRY_CODE")
  86. .IsUnique();
  87. entity.Property(e => e.Id).HasComment("Country primary key");
  88. entity.Property(e => e.Code)
  89. .HasMaxLength(5)
  90. .HasComment("Country code. Main key to search.");
  91. entity.Property(e => e.Created)
  92. .HasColumnType("datetime")
  93. .HasDefaultValueSql("(getdate())")
  94. .HasComment("Record created timestamp");
  95. entity.Property(e => e.DefaultCurrencyId).HasComment("Default country currency");
  96. entity.Property(e => e.Modified)
  97. .HasColumnType("datetime")
  98. .HasComment("Record modified timestamp");
  99. entity.Property(e => e.Modifier)
  100. .HasMaxLength(100)
  101. .HasComment("Record modifier signature");
  102. entity.Property(e => e.Name)
  103. .HasMaxLength(50)
  104. .HasComment("Country name. Informational value.");
  105. entity.Property(e => e.Vat)
  106. .HasColumnName("VAT")
  107. .HasComment("Percentage VAT definition");
  108. entity.HasOne(d => d.DefaultCurrency)
  109. .WithMany(p => p.Countries)
  110. .HasForeignKey(d => d.DefaultCurrencyId)
  111. .OnDelete(DeleteBehavior.ClientSetNull)
  112. .HasConstraintName("REL_COUNTRY_CURRENCY_ID");
  113. });
  114. modelBuilder.Entity<Currency>(entity =>
  115. {
  116. entity.ToTable("Currency", "base");
  117. entity.HasIndex(e => e.Code, "IDX_CURRENCY_ID")
  118. .IsUnique();
  119. entity.Property(e => e.Id).HasComment("Currency primary key");
  120. entity.Property(e => e.Code)
  121. .HasMaxLength(5)
  122. .HasComment("Currency code. Main key to search.");
  123. entity.Property(e => e.Created)
  124. .HasColumnType("datetime")
  125. .HasDefaultValueSql("(getdate())")
  126. .HasComment("Record created timestamp");
  127. entity.Property(e => e.Modified)
  128. .HasColumnType("datetime")
  129. .HasComment("Record modified timestamp");
  130. entity.Property(e => e.Modifier)
  131. .HasMaxLength(100)
  132. .HasComment("Record modifier signature");
  133. entity.Property(e => e.Name)
  134. .HasMaxLength(50)
  135. .HasComment("Currency name. Informational value.");
  136. entity.Property(e => e.Sign)
  137. .HasMaxLength(3)
  138. .HasComment("Currency sign chars");
  139. });
  140. modelBuilder.Entity<Customer>(entity =>
  141. {
  142. entity.ToTable("Customer", "Customer");
  143. entity.HasIndex(e => e.Code, "IDX_CUSTOMER_CODE")
  144. .IsUnique();
  145. entity.Property(e => e.Id).HasComment("Setting primary key");
  146. entity.Property(e => e.Code)
  147. .HasMaxLength(20)
  148. .HasComment("Customer code. Main key to search.");
  149. entity.Property(e => e.Created)
  150. .HasColumnType("datetime")
  151. .HasDefaultValueSql("(getdate())")
  152. .HasComment("Record created timestamp");
  153. entity.Property(e => e.Modified)
  154. .HasColumnType("datetime")
  155. .HasComment("Record modified timestamp");
  156. entity.Property(e => e.Modifier)
  157. .HasMaxLength(100)
  158. .HasComment("Record modifier signature");
  159. entity.Property(e => e.Name)
  160. .HasMaxLength(100)
  161. .HasComment("Customer head name. For identification usage.");
  162. entity.Property(e => e.TaxCountryCode)
  163. .HasMaxLength(5)
  164. .HasComment("Tax country region code");
  165. entity.Property(e => e.TaxNumber)
  166. .HasMaxLength(20)
  167. .HasComment("Customer tax number (business identifier)");
  168. entity.Property(e => e.TenantCode)
  169. .HasMaxLength(20)
  170. .HasComment("Reference to tenant code that customer belongs");
  171. entity.Property(e => e.VatIncluded)
  172. .IsRequired()
  173. .HasDefaultValueSql("((1))")
  174. .HasComment("Flag if VAT calculation is allowed");
  175. entity.Property(e => e.VatNumber)
  176. .HasMaxLength(20)
  177. .HasComment("Customer VAT number (VAT identification)");
  178. });
  179. modelBuilder.Entity<CustomerUser>(entity =>
  180. {
  181. entity.HasNoKey();
  182. entity.ToTable("CustomerUser", "Customer");
  183. entity.Property(e => e.CustomerId).HasComment("Reference to customer");
  184. entity.Property(e => e.UserLoginName)
  185. .HasMaxLength(100)
  186. .HasComment("Reference to user");
  187. entity.HasOne(d => d.Customer)
  188. .WithMany()
  189. .HasForeignKey(d => d.CustomerId)
  190. .OnDelete(DeleteBehavior.ClientSetNull)
  191. .HasConstraintName("REL_CUSTOMETUSER_CUSTOMER_ID");
  192. });
  193. modelBuilder.Entity<Setting>(entity =>
  194. {
  195. entity.ToTable("Setting", "base");
  196. entity.HasIndex(e => new { e.TenantId, e.ModuleCode, e.Code }, "IDX_SETTING_TENANT_MCODE_CODE")
  197. .IsUnique();
  198. entity.Property(e => e.Id).HasComment("Setting primary key");
  199. entity.Property(e => e.Code)
  200. .HasMaxLength(100)
  201. .HasComment("Setting code. Main key to search.");
  202. entity.Property(e => e.Created)
  203. .HasColumnType("datetime")
  204. .HasDefaultValueSql("(getdate())")
  205. .HasComment("Record created timestamp");
  206. entity.Property(e => e.Description)
  207. .HasMaxLength(500)
  208. .HasComment("Setting value description");
  209. entity.Property(e => e.IsEnabled).HasComment("Flag if setting is enabled");
  210. entity.Property(e => e.Modified)
  211. .HasColumnType("datetime")
  212. .HasComment("Record modified timestamp");
  213. entity.Property(e => e.Modifier)
  214. .HasMaxLength(100)
  215. .HasComment("Record modifier signature");
  216. entity.Property(e => e.ModuleCode)
  217. .HasMaxLength(10)
  218. .HasComment("Module code that setting belongs. Secondary key");
  219. entity.Property(e => e.ParentId).HasComment("Reference to parent setting");
  220. entity.Property(e => e.SequenceNo).HasComment("Order number");
  221. entity.Property(e => e.TenantId).HasComment("Reference to tenant that setting belongs");
  222. entity.Property(e => e.Value).HasComment("Setting value");
  223. entity.Property(e => e.ValueTypeQualified)
  224. .HasMaxLength(500)
  225. .HasComment("Qualified name of value type");
  226. entity.HasOne(d => d.Parent)
  227. .WithMany(p => p.InverseParent)
  228. .HasForeignKey(d => d.ParentId)
  229. .HasConstraintName("REL_SETTING_SETTING_ID");
  230. entity.HasOne(d => d.Tenant)
  231. .WithMany(p => p.Settings)
  232. .HasForeignKey(d => d.TenantId)
  233. .OnDelete(DeleteBehavior.ClientSetNull)
  234. .HasConstraintName("REL_SETTING_TENANT_ID");
  235. });
  236. modelBuilder.Entity<Tenant>(entity =>
  237. {
  238. entity.ToTable("Tenant", "base");
  239. entity.HasIndex(e => e.Code, "IDX_TENANT_CODE")
  240. .IsUnique();
  241. entity.Property(e => e.Id).HasComment("Tenant primary key");
  242. entity.Property(e => e.Code)
  243. .HasMaxLength(20)
  244. .HasComment("Tenant code. Main key to search.");
  245. entity.Property(e => e.Created)
  246. .HasColumnType("datetime")
  247. .HasDefaultValueSql("(getdate())")
  248. .HasComment("Record created timestamp");
  249. entity.Property(e => e.IsLocked).HasComment("Flag if tenant locked (not accessable)");
  250. entity.Property(e => e.LastAccess)
  251. .HasColumnType("datetime")
  252. .HasComment("Last access (usage) timestamp.");
  253. entity.Property(e => e.Modified)
  254. .HasColumnType("datetime")
  255. .HasComment("Record modified timestamp");
  256. entity.Property(e => e.Modifier)
  257. .HasMaxLength(100)
  258. .HasComment("Record modifier signature");
  259. entity.Property(e => e.Name)
  260. .HasMaxLength(200)
  261. .HasComment("Tenant name. Informational value.");
  262. });
  263. modelBuilder.Entity<TenantCountry>(entity =>
  264. {
  265. entity.HasNoKey();
  266. entity.ToTable("TenantCountry", "base");
  267. entity.Property(e => e.CountryId).HasComment("Reference to country");
  268. entity.Property(e => e.TenantId).HasComment("Reference to tenant");
  269. entity.HasOne(d => d.Country)
  270. .WithMany()
  271. .HasForeignKey(d => d.CountryId)
  272. .OnDelete(DeleteBehavior.ClientSetNull)
  273. .HasConstraintName("REL_TENANTCOUNTRY_COUNTRY_ID");
  274. entity.HasOne(d => d.Tenant)
  275. .WithMany()
  276. .HasForeignKey(d => d.TenantId)
  277. .OnDelete(DeleteBehavior.ClientSetNull)
  278. .HasConstraintName("REL_TENANTCOUNTRY_TENANT_ID");
  279. });
  280. modelBuilder.Entity<TenantCurrency>(entity =>
  281. {
  282. entity.HasNoKey();
  283. entity.ToTable("TenantCurrency", "base");
  284. entity.Property(e => e.CurrencyId).HasComment("Reference to currency");
  285. entity.Property(e => e.TenantId).HasComment("Reference to tenant");
  286. entity.HasOne(d => d.Currency)
  287. .WithMany()
  288. .HasForeignKey(d => d.CurrencyId)
  289. .OnDelete(DeleteBehavior.ClientSetNull)
  290. .HasConstraintName("REL_TENANTCURRENCY_CURRENCY__ID");
  291. entity.HasOne(d => d.Tenant)
  292. .WithMany()
  293. .HasForeignKey(d => d.TenantId)
  294. .OnDelete(DeleteBehavior.ClientSetNull)
  295. .HasConstraintName("REL_TENANTCURRENCT_TENANT_ID");
  296. });
  297. modelBuilder.Entity<TenantUser>(entity =>
  298. {
  299. entity.HasNoKey();
  300. entity.ToTable("TenantUser", "base");
  301. entity.Property(e => e.TenantId).HasComment("Reference to tenant");
  302. entity.Property(e => e.UserId).HasComment("Reference to user");
  303. entity.HasOne(d => d.Tenant)
  304. .WithMany()
  305. .HasForeignKey(d => d.TenantId)
  306. .OnDelete(DeleteBehavior.ClientSetNull)
  307. .HasConstraintName("REL_TENANTUSER_TENANT_ID");
  308. entity.HasOne(d => d.User)
  309. .WithMany()
  310. .HasForeignKey(d => d.UserId)
  311. .OnDelete(DeleteBehavior.ClientSetNull)
  312. .HasConstraintName("REL_TENANTUSER_USER_ID");
  313. });
  314. modelBuilder.Entity<User>(entity =>
  315. {
  316. entity.ToTable("User", "base");
  317. entity.HasIndex(e => e.LoginName, "IDX_USER_LOGINNAME")
  318. .IsUnique();
  319. entity.Property(e => e.Id).HasComment("User primary key");
  320. entity.Property(e => e.Created)
  321. .HasColumnType("datetime")
  322. .HasDefaultValueSql("(getdate())")
  323. .HasComment("Record created timestamp");
  324. entity.Property(e => e.IsLocked).HasComment("Flag if user access locked (not accessable)");
  325. entity.Property(e => e.LoginName)
  326. .HasMaxLength(100)
  327. .HasComment("User login name name. Key search value");
  328. entity.Property(e => e.Modified)
  329. .HasColumnType("datetime")
  330. .HasComment("Record modified timestamp");
  331. entity.Property(e => e.Modifier)
  332. .HasMaxLength(100)
  333. .HasComment("Record modifier signature");
  334. });
  335. OnModelCreatingPartial(modelBuilder);
  336. }
  337. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  338. }
  339. }