Thursday, November 26, 2015

C# Expression in Dynamic Linq Queries

Currently dynamic linq operators created using System.Linq.Expressions.Expression object do not support sql "IN" operator, there is a way to implement it however, just add a simple expression building tree like in the example here:

pe = Expression.Parameter(typeof(myClient), "clt"); PropertyInfo propertyInfo = typeof(myClient).GetProperty("PropertyFieldName"); MemberExpression m = Expression.MakeMemberAccess(pe, propertyInfo); ConstantExpression c = Expression.Constant("SearchFrase", typeof(string)); MethodInfo mi = typeof(string).GetMethod("Contains", new Type[] { typeof(string) }); e1 = exp.Expression.Call(m, mi, c);


Reference: 

http://stackoverflow.com/questions/6907103/how-to-create-a-dynamic-contains-or-like-expression-to-be-used-with-linq-again



Friday, November 13, 2015

Default boolean value in Entity Framework

To set a default value to bit column in EF edit the migration file manaully and add defaultvaluesql parameter like

AddColumn("Jobs", "IsAdvertisingRequired", c => c.Boolean(nullable: false, defaultValueSql: "0"));
 
 Reference: http://stackoverflow.com/questions/5567567/default-bool-to-false-when-null-in-database-with-entity-framework-4-1-code-first

ORM performance

The article below explains some scenarios where Linq-2-SQL can be slower than expected and a easy fix for them.

http://samsaffron.com/archive/2011/03/30/How+I+learned+to+stop+worrying+and+write+my+own+ORM

Also was attracted by the idea of single file ORM

https://github.com/FransBouma/Massive

Thursday, November 12, 2015

Re Linq Provider - could be great fun to implement

While linq is definitely a powerful framework to query against databases, it is also somewhat complex to understand and use (and even more difficult if we are writing custom providers).

Writing a custom Re Linq provider seems to be a little simpler process, however there are very few help articles at the moment. I have found one very useful article on this topic and hence just keeping a note to myself..

http://fairwaytech.com/2013/03/writing-a-custom-linq-provider-with-re-linq/

Monday, November 9, 2015

Creating Northwind sample database on SQL 2014

A while ago there was a situation where I needed the northwind database on SQL 2014 instance, which is originally available in SQL 2000 script format at

https://www.microsoft.com/en-us/download/details.aspx?id=23654

But the sp_dboptions system sp has been deprecated in SQL 2012 onwards so I needed to replace the following lines

--exec sp_dboption 'Northwind','trunc. log on chkpt.','true'
--exec sp_dboption 'Northwind','select into/bulkcopy','true'

with

ALTER DATABASE Northwind SET RECOVERY SIMPLE 
ALTER DATABASE Northwind SET RECOVERY BULK_LOGGED

And it works like a charm :)

More reference about the new commands can be found at http://beyondrelational.com/modules/2/blogs/28/Posts/15429/replacement-for-system-stored-procedure-spdboption-in-sql-server-2012-denali.aspx

Friday, November 6, 2015

Very good tool to copy HTML snippets

It was always a tedious task to copy HTML along with stylesheet to another page, but with this extension this is as simple as a click, however I would have liked to see an option to add HTML inline.


https://chrome.google.com/webstore/detail/snappysnippet/blfngdefapoapkcdibbdkigpeaffgcil



Wednesday, November 4, 2015

Disable bundling in MVC

I was searching for a while to disable bundling in MVC in debug mode to be able to debug the files quickly and I ended up on these posts in google search, it is definitely interesting to know these customizations.

http://blog.kurtschindler.net/disabling-bundling-and-minification-in-asp-net-4-5mvc-4/

https://gist.github.com/zaus/7436601

http://stackoverflow.com/questions/20397452/custom-bundle-in-mvc-4-is-not-rendered

There might be many more articles on the web, but this was just a quick search..

Secure micro services using jwt and ocelot

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