How to add a description in the column?

Asked

Viewed 75 times

2

I am using Firts Migration to update in MS SQL SERVER Database.

In class ApplicationDBContext, has a method OnModelCreating where you can rename table, change data type, set your keys, etc...

In this method OnModelCreating, I can put the description of the column ?

Following example:

inserir a descrição da imagem aqui

  • 2

    Check here https://stackoverflow.com/questions/10080601/how-to-add-description-to-columns-in-entity-framework-4-3-code-first-using-migra

1 answer

0

Hi, Matheus. All right?

I have no experience with First Migration, but maybe I can open up the possibilities.

In SQL Server this type of information is stored in an Extended Properties table.

In the same way that you generated the scripts of the tables and their respective data to be migrated, I understand that, just migrate the data from this property table extended by the First Migration script.

Follow below some procedures that can help you, or at least give you a north.

USE AdventureWorks;  

CREATE TABLE dbo.T1 (id int , name char (20));  


--Adiciona a propriedade extendida 
EXEC sp_addextendedproperty   
     @name = N'Caption'  
    ,@value = N'Employee ID'  
    ,@level0type = N'Schema', @level0name = dbo  
    ,@level1type = N'Table',  @level1name = T1  
    ,@level2type = N'Column', @level2name = id;  


--Atualiza a propriedade extendida 
EXEC sp_updateextendedproperty   
     @name = N'Caption'  
    ,@value = 'Employee ID must be unique.'  
    ,@level0type = N'Schema', @level0name = dbo  
    ,@level1type = N'Table',  @level1name = T1  
    ,@level2type = N'Column', @level2name = id;  


--Consulta propriedades extendidas 
SELECT  major_id, minor_id, t.name AS [Table Name], c.name AS [Column Name],  
        ep.name AS [Extended Property name], ep.value AS [Extended Property value]
FROM sys.extended_properties AS ep
INNER JOIN sys.tables AS t ON ep.major_id = t.object_id 
INNER JOIN sys.columns AS c ON ep.major_id = c.object_id AND ep.minor_id = c.column_id
WHERE class = 1
and t.name = 'T1'

I hope this helps you. If you need help you can contact me, I’ll be happy to help.

Abs. Welricsson Carmo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.