You can create a stored procedure and call it from EF passing in the table names, or run the raw sql command:
var sqlToRun = string.format(@"SELECT column_name as 'Column Name', data_type as 'Data Type', character_maximum_length as 'Max Length' FROM information_schema.columns WHERE table_name = '{0}'", myTableName); using (var context = new dbContext()) { var tableFieldDetails= context.SqlQuery(sqlToRun).ToList();
... where myTableName is the name of the table to return the field information from.
Note that -1 if you are using nvarchar(MAX) or varchar(MAX) , and I am sure there may be some other anomalies, since I have not tested all types.
Also, I have not tested C # above, so it may require tuning to work, but the principle is good and will benefit from encapsulation in a good method; -)
For more information on running raw sql in EF, see https://msdn.microsoft.com/en-us/data/jj592907.aspx
source share