You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DataSource.twig 1.4KB

123456789101112131415161718192021222324252627282930
  1. using Microsoft.EntityFrameworkCore;
  2. using Luticate2.Auth.DataAccess.Models;
  3. namespace Luticate2.Auth.DataAccess
  4. {
  5. public partial class LuDatabaseContext : DbContext
  6. {
  7. public LuDatabaseContext(DbContextOptions options) :base(options)
  8. {
  9. }
  10. protected override void OnModelCreating(ModelBuilder modelBuilder)
  11. {
  12. {% for table in dataSource.getTables() %}{% if (table.hasAny()) %}
  13. modelBuilder.Entity<{{ table.getName() }}>()
  14. .HasKey(c => new { {% for column in table.getPrimaryKeys() %}{% if (column.isSelected()) %}c.{{ column.getName() }}{% if not (loop.last) %}, {% endif %}{% endif %}{% endfor %} });
  15. {% for fk in table.getSourceForeignKeys() %}
  16. modelBuilder.Entity<{{ fk.getSourceTable().getName() }}>()
  17. .HasOne(e => e.{{ fk.getSourceForeignKeyName() }})
  18. .WithMany(e => e.{{ fk.getTargetForeignKeyName() }})
  19. .HasForeignKey("{% for column in fk.getSourceColumns() %}{{ column.getName }}{% if not (loop.last) %}, {% endif %}{% endfor %}")
  20. .HasConstraintName("{{ fk.getName() }}");
  21. {% endfor %}
  22. {% endif %}{% endfor %}
  23. }
  24. {% for table in dataSource.getTables() %}{% if (table.hasAny()) %}
  25. public DbSet<{{ table.getName() }}> {{ table.getName() }} { get; set; }
  26. {% endif %}{% endfor %}
  27. }
  28. }