jeudi 8 décembre 2016

How to export all EF EntityTypeConfiguration mapping lasses to a csv file with the mapping details of each properties using reflection in C#?

Sample Class:

public class DocumentMap : EntityTypeConfiguration<DocumentEntity>
{
    public DocumentMap()
    {
        // Primary Key
        this.HasKey(t => t.ID);

        // Properties
        this.Property(t => t.ID)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

        this.Property(t => t.Name)
            .IsRequired();

        this.Property(t => t.DocumentLocationID)
          .IsRequired();

        this.Property(t => t.DocumentUrl)
         .IsRequired();

        this.Property(t => t.DocumentTypeID)
        .IsRequired();

        this.Ignore(t => t.DocumentType);
        this.Ignore(t => t.DocumentLocation);
        this.Ignore(t => t.Document);
        this.Ignore(t => t.FilePath);
        this.Ignore(t => t.FileType);
        this.Ignore(t => t.TemporaryURL);
        this.Ignore(t => t.DestinationPath);
        //this.Ignore(t => t.DestinationURL);

        // Table & Column Mappings
        this.ToTable("DOCUMENT");
        this.Property(t => t.ID).HasColumnName("DOC_ID");
        this.Property(t => t.Name).HasColumnName("DOC_NM");
        this.Property(t => t.DocumentLocationID).HasColumnName("DOC_REF_LOC_TP_RD_ID");
        this.Property(t => t.DocumentUrl).HasColumnName("DOC_REF_URL");
        this.Property(t => t.DocumentTypeID).HasColumnName("DOC_TYPE_RD_ID");
        this.Property(t => t.DocumentVersion).HasColumnName("DOC_VERSION");
        this.Property(t => t.DocumentReceivedBy).HasColumnName("DOC_RECEIVED_BY");
        this.Property(t => t.DocumentReceivedDt).HasColumnName("DOC_RECEIVED_DT");
        this.Property(t => t.IsDocumentDelivered).HasColumnName("DOC_DELIVERED_FLG");
    }
}

The output should be like: Class name, Property name, Table name, Colmun name. Eg:

ModelClass      PropertyName TableName TableColumn 
DocumentEntity  ID           DOCUMENT  DOC_ID
DocumentEntity  Name         DOCUMENT  DOC_NM

This should be exported to a CSV file using c# so that the CSV file contains ModelClass, PropertyName, TableName and TableColumn





Aucun commentaire:

Enregistrer un commentaire