Automatic generation of EF entities and mappings from existing database schema

This is  a bunch of useful scripts for generating C# Entity Framework Code First POCOs from existing database schema.

First, let’s create T-SQL function for generating C# class for EF entity:

This function deliberately ignores certain columns, (Created On/By, Modified On/By). This properties are pushed to EntityBase class, which our POCO inherits from. All other columns in DB table will be mapped to corresponding C# type.

Next, let’s create T-SQL function for EF configuration (mapping class):

Now, let’s put it all together in one script:

All source code is available here



Git aliases I can’t live without

Being still quite new to git (and moving from world of VSS/TFS), I became big fan of Git’s flexibility and configuration. It really boosts productivity and makes developer’s life much easier. Below I list git aliases I found most useful. For sure this list will grow in future.

 

Unit Testing stack for C#/Visual Studio

After spending some time on digging through unit testing components, I ran into a setup I am finally happy with. This consists of: https://github.com/AutoFixture – acts as DI container/object factory, significantly improving unit test maintainability https://github.com/moq – awesome mocking framework, fully integrated with AutoFixture https://www.nuget.org/packages/SemanticComparison – excellent utility for comparing instances https://github.com/shouldly/shouldly – great for simplifying assertion statements https://github.com/xunit/xunit – superb […]

T-SQL Tricks

Few useful SQL tricks: Move table to different schema

Rename object

Simplest way to restore MSSQL Server database

Here’s a simplest way I found (so far) to restore a database in MS SQL Server. First part lists “logicalnames” from the backup that you want to restore. Modify the path so it points to the actual path where your backup file is:

This shows LogicalName and PhysicalName of the data and log backup […]

Next Page »