Tuesday, October 20, 2015

Count number of selectors in a css file

IE9 allows only 4095 css selectors, hence we need to know number of css selectors in a file

http://stackoverflow.com/questions/5228459/count-number-of-selectors-in-a-css-file

Also, there are some very good tools like Dust-Me Data (firefox) or CSS Remove and Combine (Chrome) which give a statistics about number of used and unused selectors.


Monday, October 19, 2015

Custom Linq Provider: Enabling a Data Source for LINQ Querying

These are msdn articles explaining the steps in detail about building a custom linq query provider, but be prepared to run through a highly complex framework before reading them.

https://msdn.microsoft.com/en-us/library/bb882640.aspx
http://blogs.msdn.com/b/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx

http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx

This a really helful source  code of sample project which implements few custom linq providers for different data source types sql ce, mysql, access, sqllite, etc.

http://iqtoolkit.codeplex.com/

The source code above works with sql 2005, however current sql versions do not support .mdf file attachments through code, hence after migrating the Northwind database to SQL 2014 version, I had to change DbEntityProvider.From method as below

if (provider == null)
            {
                var clower = connectionString.ToLower();
                // try sniffing connection to figure out provider
                if (clower.Contains(".mdb") || clower.Contains(".accdb"))
                {
                    provider = "IQToolkit.Data.Access";
                }
                else if (clower.Contains(".sdf"))
                {
                    provider = "IQToolkit.Data.SqlServerCe";
                }
                else if (clower.Contains(".sl3") || clower.Contains(".db3"))
                {
                    provider = "IQToolkit.Data.SQLite";
                }
                else if (clower.Contains(".mdf"))
                {
                    provider = "IQToolkit.Data.SqlClient";
                }
                else
                {
                    //throw new InvalidOperationException(string.Format("Query provider not specified and cannot be inferred."));
                    provider = "IQToolkit.Data.SqlServer";
                }

And SqlServerQueryProvider class like:

public static string GetConnectionString(string connectionString)
        {
            //return string.Format(@"Data Source=.\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=true;AttachDbFilename='{0}'", databaseFile);
            //return string.Format(@"Data Source=.\QLEXPRESS;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=true;AttachDbFilename='{0}'", databaseFile);
            return connectionString;
        }

Also I had to pass the actual connection string to  DbEntityProvider.From method like:

var provider = DbEntityProvider.From("Data Source=<SQL Server Name>;Initial Catalog=Northwind;Integrated Security=True", "Test.NorthwindWithAttributes");

Thursday, October 1, 2015

Entity Framework Default database values

Entity framework can be modified to have a default value in database as opposed to in EDMX file using the downloaded code in this blog. Good article really!

http://www.codeproject.com/Articles/89191/Entity-Framework-EDMX-Modifier-Correct-Default-V

Productivity Tools

This is an interesting article about drawbacks productivity tools, but part which I liked most is where the author directs us to technologies which possibly will be very important in the future.

http://blog.ploeh.dk/2013/02/04/BewareofProductivityTools/

Secure micro services using jwt and ocelot

  Secure Microservices Using JWT With Ocelot in .NET Core (code-maze.com)