Posts

EntityFramework Reverse POCO Code First Generator

Reverse engineers an existing database and generates EntityFramework Code First POCO classes, Configuration mappings and DbContext. To install and use this project: Use Nuget and install EntityFramework. Add a connect string to your app.config. Somethine like: In Visual Studio, right click project and select "add - new item". Select Online, and search for "reverse poco". Or you can download it from this page. Select "EntityFramework Reverse POCO Code First Generator". Give the file a name, such as Database.tt and click Add. Edit the Database.tt file and specify the connection string as MyDbContext which matches your name in app.config. Save the Database.tt file, which will now generate the Database.cs file. To see a video, head over to http://visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838

Obtaining the database schema, tables, columns, and primary keys in a single SQL call

I am currently writing an EntityFramework reverse engineer code-first generator. It will generate POCO classes, DbContext and Code First mapping for an existing database. There is one already in Entity Framework Power Tools Beta 2 However this one is going to do the job right, and include table filtering! Watch this space... SELECT [Extent1].[SchemaName], [Extent1].[Name] AS TableName, [Extent1].[TABLE_TYPE] AS TableType, [UnionAll1].[Ordinal], [UnionAll1].[Name] AS ColumnName, [UnionAll1].[IsNullable], [UnionAll1].[TypeName], ISNULL([UnionAll1].[MaxLength],0) AS MaxLength, ISNULL([UnionAll1].[Precision], 0) AS Precision, ISNULL([UnionAll1].[Default], '') AS [Default], ISNULL([UnionAll1].[DateTimePrecision], '') AS [DateTimePrecision], ISNULL([UnionAll1].[Scale], 0) AS Scale, [UnionAll1].[IsIdentity], [UnionAll1].[IsStoreGenerated], CASE WHEN ([Project5...

FizzBuzz generators

SQL WITH mil AS ( SELECT TOP 1000000 ROW_NUMBER() OVER ( ORDER BY c.column_id ) [n] FROM master.sys.all_columns as c CROSS JOIN master.sys.all_columns as c2 ) SELECT CASE WHEN n % 3 = 0 THEN CASE WHEN n % 5 = 0 THEN 'FizzBuzz' ELSE 'Fizz' END WHEN n % 5 = 0 THEN 'Buzz' ELSE CAST(n AS char(6)) END + CHAR(13) FROM mil C# foreach (int number in Enumerable.Range(1, 100)) { bool isDivisibleBy3 = (number % 3) == 0; bool isDivisibleBy5 = (number % 5) == 0; if (isDivisibleBy3) Console.Write("Fizz"); if (isDivisibleBy5) Console.Write("Buzz"); if (!isDivisibleBy3 && !isDivisibleBy5) Console.Write(number); Console.WriteLine(); } C# linq Enumerable .Range(1, 100) .Select(i => i % 15 == 0 ? "FizzBuzz" : i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : i.ToString()) .ToList() .For...

SQL Lotter number selector

Just a bit of fun with SQL WITH L0 AS (SELECT 0 AS C UNION ALL SELECT 0), L1 AS (SELECT 0 AS C FROM L0 AS A CROSS JOIN L0 AS B), L2 AS (SELECT 0 AS C FROM L1 AS A CROSS JOIN L1 AS B), L3 AS (SELECT 0 AS C FROM L2 AS A CROSS JOIN L2 AS B), Nums AS (SELECT TOP(49) ROW_NUMBER() OVER(ORDER BY (SELECT 0)) AS n FROM L3 ORDER BY n), Choice AS (SELECT TOP(6) n FROM Nums ORDER BY CHECKSUM(NEWID())) SELECT STUFF( (SELECT ',' + CAST(n AS VARCHAR(10)) AS [text()] FROM Choice ORDER BY n FOR XML PATH('')), 1, 1, '')

Effortless .Net Encryption

I've just released a new open source project called Effortless .Net Encryption. It can be found here: https://github.com/sjh37/Effortless-.Net-Encryption Effortless .Net Encryption is a library that is written in C# 4.0, contains 68 unit tests and 190 Pex unit tests, and provides: Rijndael encryption/decryption. Hashing and Digest creation/validation. Password and salt creation. Available on Nuget https://nuget.org/packages/Effortless.Net.Encryption/ To install Effortless.Net.Encryption, run the following command in the Package Manager Console Install-Package Effortless.Net.Encryption

A generic singleton using Lazy< T >

Carring on from the generic singleton post here. Since we have .NET 4, we can now make use of Lazy public class Singleton where T : class, new() { private Singleton() {} private static readonly Lazy instance = new Lazy (() => new T()); public static T Instance { get { return instance.Value; } } }

Please turn off hyperlinks in PowerPoint

Image
When giving presentations, you should really turn off PowerPoints AutoCorrect feature of it changing a hyperlink into an underlined link. Unless you actually are going to click on the link during the presentation, then turn it off. It's much easer to read without it being in a different font and underlined. To turn it off in PowerPoint, goto Tools -> Options -> Proofing -> AutoCorrect options. Untick the box highlighted below.