This post is about a new library CExtensions-EFModelGenerator for generating poco and dbcontext classes from Oracle or Sqlserver databases. (support for other databases can be provided through customization).
with this library it could also be possible to generate code for java, javascript and other by implementing a custom Serializer (check the Test for mor info and more samples).
This post guides you through how to generate code from Sqlserver. (also check the Sample folder in the repo)
Create a new console project
Add a config file (ending with .json) : Models.json (replace ConnectionString
with yours
[code lang=javascript] { "Options": { "ElementToGenerate": "All", "SchemaName": "dbo", "ConnectionString": "Server=MC0QKBSC\SQLEXPRESS;Database=YOURDB;TrustedConnection=True;", "Namespace": "My.Own.Namespace", "IgnoreTableRegex": [ "^backup" ], "ColumnNameFormatters": [ { "Name": "CExtensions.EFModelGenerator.Formatters.IDColumnFormatter"}, { "Name": "CExtensions.EFModelGenerator.Formatters.SafeIdColumnNameFormatter" }, { "Name": "CExtensions.EFModelGenerator.Formatters.RemoveTillFirstUnderscoreNameFormatter", "Params": [ [ "Coltag", "Tbl_tag" ] ] }, { "Name": "CExtensions.EFModelGenerator.Formatters.UpperFirstLetterNameFormatter" } ]
}
} [/code]
[code lang=csharp] class Program { static void Main(string[] args) { string pathToYourJson = @"C:\projects\cextensions\CExtensions-EFModelGenerator\src\Sample\SimpleSample\Models.json"
Generator.Generate(pathToYourJson);
}
} [/code]
you can add this file to your project and add the required packages to get it compiled (EF and System.ComponentModel.DataAnnotations.dll should be in the reference) check the Test folder to see what you can generate and how That's it ! note : - A visual studio extension is under development. - Check GenerationOptions for more info on all Generation option you can provide