Develop a C# solution that retrieves a table definition from a SQL Server database and generates the C# source code representing the table as a C# class. The SQL used to obtain the table information is shown below.
SELECT
C.object_id,
C.name as 'column_name',
C.column_id,
C.system_type_id,
T.name as 'system_type_name',
C.max_length,
C.is_nullable
FROM SYS.columns C, SYS.types T
WHERE C.system_type_id = T.system_type_id AND
C.object_id = (SELECT object_id FROM SYS.TABLES WHERE name = 'STTOO1_STUDENT')
ORDER BY C.column_id;
Query Results:
An example output for this program is shown below.
public class Student
{
public int Id {get; set; }
public decimal GPA { get; set; }
public string MajorCode { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Even though the program is not yet complete, there is a buzz around the office about how helpful this feature will be for other databases (e.g., Oracle, SQLite, MySQL, etc.) in addition to SQL Server, so the design should support extending the application to support additional source databases as enhancements in future. Additionally, there is a discussion of supporting other language outputs, including Java, C++, Visual Basic, and Python; however, the initial deployment is only required to support the C# programming language.