Created
March 11, 2019 17:21
-
-
Save renant/aee21395d0fbd2477f070d73e35ad9fc to your computer and use it in GitHub Desktop.
Gerador de Map do entity a partir de uma tabela
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @schema varchar(100) = 'schema' | |
declare @tableName varchar(100) = 'tableName' | |
declare @objectId bigint; | |
select @objectId = t.object_id | |
from sys.tables t | |
inner join sys.schemas s on s.schema_id = t.schema_id | |
where s.name = @schema and t.name = @tableName | |
select concat(' public class ', @tableName, 'MapSqlServer : IEntityTypeConfiguration<',@tableName,'>') | |
union all | |
select ' {' | |
union all | |
select concat(' public void Configure(EntityTypeBuilder<',@tableName, '> builder)') | |
union all | |
select ' {' | |
union all | |
select concat(' builder.ToTable("',@tableName,'", "',@schema,'");') | |
union all | |
select ' builder.HasKey(x => x.Id);' | |
union all | |
select concat(' builder.Property(x => x.',c.name,').HasColumnName("',c.name,'");') | |
from sys.columns c | |
where object_id = @objectId | |
union all | |
select ' builder.Property(p => p.Id).UseSqlServerIdentityColumn();' | |
union all | |
select ' }' | |
union all | |
select ' }' | |
select @objectId; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
créditos a https://github.com/souzara