{"id":14994143,"url":"https://github.com/karenpayneoregon/classes-from-sqlserver","last_synced_at":"2025-04-30T16:25:07.536Z","repository":{"id":110840374,"uuid":"382399958","full_name":"karenpayneoregon/classes-from-sqlserver","owner":"karenpayneoregon","description":"Sample code to create classes from sql-server database","archived":false,"fork":false,"pushed_at":"2022-12-27T15:05:41.000Z","size":147,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T17:51:08.525Z","etag":null,"topics":["csharp","netcore5","sqlserver","windowsforms"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karenpayneoregon.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-02T16:14:45.000Z","updated_at":"2024-01-05T19:45:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"efc6c406-53a9-4247-9349-8e99b09f301b","html_url":"https://github.com/karenpayneoregon/classes-from-sqlserver","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":"0.045454545454545414","last_synced_commit":"529079e45184ef8037ab0c6ba427211d7988d4b3"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fclasses-from-sqlserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fclasses-from-sqlserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fclasses-from-sqlserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fclasses-from-sqlserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karenpayneoregon","download_url":"https://codeload.github.com/karenpayneoregon/classes-from-sqlserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251740956,"owners_count":21636162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","netcore5","sqlserver","windowsforms"],"created_at":"2024-09-24T16:00:32.368Z","updated_at":"2025-04-30T16:25:07.495Z","avatar_url":"https://github.com/karenpayneoregon.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Classes from SQL-Server for C# and VB.NET\n\n\nCode presented provides a developer with a tool to generate classes from a database. \n\nAn alternate is to install the following Visual Studio [extension](http://www.gui-innovations.com/visual-studio-add-ins/paste-sql-classes.html) which requires a developer to open SQL-Server Management Studio (SSMS), select a table, right click and select CREATE To Clipboard and repeat for each table.\n\nWhile the code in this repository allow a developer to create classes for an entire database at the click of a button and places these classes in a folder, ready to use but recommend adding your namespace to each class.\n\n![img](assets/classGenScreenShot.png)\n\nSupports `VB.NET` and `C#` (written in C#)\n\n![img](assets/Figure1.png)\n\nCode presented here provide methods to `create concrete classes` from `SQL-Server database tables` written with Microsoft Visual Studio 2019, C#, .NET Core 5.\n\nWhen use of conventional DataSet/DataTable to store data are too heavy, similarly Entity Framework is overkill creating simple classes can be a great solution. \n\nWhen there are a handful of columns in a database table it's easy to hand code a class with properties to store data while a table with many columns may be cumbersome to write by hand. \n\nWithin this repository is a Windows Form project which creates concrete classes for a select database.\n\n# How to use\n\n* In the form load event in the project `CreateClassesFromSqlServer` change the server name if not using SQL-Express edition of SQL-Server to your server name.\n\n```csharp\nDataOperations.Server = \".\\\\SQLEXPRESS\";\n```\n\n* Set the project `CreateClassesFromSqlServer` as the startup project\n* Build the project `CreateClassesFromSqlServer`\n* Start the project\n* Select a database in the listbox\n* Click Run/Create button\n\nOnce clicking the Run/Create button a folder is created under the application folder named Classes, the classes are create under `Classes\\DatabaseNamme`.\n\nExample\n\n![img](assets/generated.png)\n\nCopy all or required classes to your project and add a namespace if so desired.\n\n\n\n\nOriginally written to answer a stackoverflow [question](https://stackoverflow.com/questions/68225326/how-to-create-a-models-class-from-sql-server) to Declarate each \nproperty with a specific property attribute using a select statement found in `ClassQuery.txt`. Have changed to the code to exclude the property attribute using a \nquery in `ClassQueryPlain.txt`\n\nNo guarantees that the code fits all situations\n\n# Test project\n\nThe project `DataLibraryTestProject` uses one of the classes generated with the addition of editing the class and adding a namespace.\n\n# Requires\n\n- Visual Studio 2019 or higher\n- NuGet package [System.Data.SqlClient](https://www.nuget.org/packages/System.Data.SqlClient/)\n\n# Important\n\nIn some cases the type for a property may not be known and in these cases will have `UNKNOWN` prepended to the SQL-Server type. In these cases a conversion will be needed.\n\nFor example [hierarchyid] needs to be parses using [SqlHierarchyId.Parse](https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ee642858(v=sql.105)?redirectedfrom=MSDN) via a read-only property.\n\n![img](assets/unknown.png)\n\n\n# Note\n\nBase code from a [Stackoverflow post](https://stackoverflow.com/questions/5873170/generate-class-from-database-table) to a response for a [question](https://stackoverflow.com/questions/68225326/how-to-create-a-models-class-from-sql-server).\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fclasses-from-sqlserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarenpayneoregon%2Fclasses-from-sqlserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fclasses-from-sqlserver/lists"}