My Software Notes

Useful things I discover

Entity Framework: Contains() (aka ‘Like’) is case insensitive for SQL Server queries

leave a comment »

Just a note to self.

The Contains method on String when used in an Entity Framework “where” clause is case insensitive.

Example:

Assume the “NoteContent” column on the table “Notes” is a varchar column. If I run the following Linq query against the database where db is a DbContext then I get the same result every time.

var num = db.Notes.Where(n => n.NoteContent.Contains(“NoTe”)).Count();

var num = db.Notes.Where(n => n.NoteContent.Contains(“NOTE”)).Count();

var num = db.Notes.Where(n => n.NoteContent.Contains(“note”)).Count();

All produce the same value for “num”.

I’m making this note to self because I keep forgetting and because I keep seeing people do this:

var someString = “whatever”;

var num = db.Notes.Where(n => n.NoteContent.ToUpper().Contains(someString.ToUpper())).Count();

And, to quote Led Zepplin, “It makes me wonder.”

Written by gsdwriter

December 2, 2014 at 9:53 am

Posted in .NET, Database, LINQ

Forcing Visual Studio to produce an XML Serializers DLL

leave a comment »

A friend needed the Xml Serializers dll, the one named something like “ClassLibrary1.XmlSerializers.dll”, so he went into the project properties in VS and set “Build > Generate serialization assembly” to “On”.  But nothing happened.  No XmlSerializers dll was created.

We hunted round for an answer and came across this: Generating an Xml Serialization assembly as part of my build.

Quick answer:

After setting the above project property you must go into the project file in your favorite text editor and add this:

<SGenUseProxyTypes>false</SGenUseProxyTypes>

 

just after the line:

<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>

 

You should end up with something like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
    <SGenUseProxyTypes>false</SGenUseProxyTypes>
  </PropertyGroup>

 

Do that for every build configuration where you need the serializer.

Hope that helps.

Written by gsdwriter

July 28, 2014 at 11:39 am

Entity Framework Generates Weird SQL

leave a comment »

If you ever see Entity Framework code that looks something like this:

SELECT
1 AS [C1],
CAST(NULL AS int) AS [C2],
CAST(NULL AS int) AS [C3],
CAST(NULL AS varchar(1)) AS [C4]
FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]
WHERE 1 = 0

and your EF LINQ query was nothing like it (and who’s would be?), then you probably have a

somelist.Contains(x.Value)

in your query and the collection “somelist” is empty.

I hit this today and was scratching my head until I found this:  

LINQ to Entity Framework submits meaningless query to SQL Server for Contains(empty array)

Hope that helps someone.

 

Written by gsdwriter

July 17, 2014 at 5:14 pm

Environmental Variables Disappearing In Windows

leave a comment »

I started noticing it a couple of days ago: icons on my task bar, such as the File Explorer, stopped working and gave me that annoying “application cannot be found” message. Other programs just stopped working.

I hunted around and found that my PATH variable in a console window was only listing the additional path items from the “User” environment. The “System” (aka “Machine”) PATH environmental variable was not being appended to the front of the “User” PATH.

I tried to open “Computer > Properties > Advanced Properties” and it said it couldn’t find the Advanced Properties dialog and it gave the path to the app using “%windir%”.  So I opened up a console and typed “SET” and the majority of the System environmental variables were missing.

What was going on?

I hunted and hunted and finally found this: Windows 7’s PATH and environment variables are corrupted.

Can you believe that? When your path goes over 2048 characters long the entire environmental variables handling in Windows goes haywire.

I edited my PATH and took out a bunch of duplicate entries (what added those?), got it down to a much smaller size and suddenly my Win7 machine was working perfectly again.

It seems like a serious omission that Windows gives no warning at all that there is a problem and we poor buggers have to figure out what to do.

I hope this post helps someone out there with the same headache.

Written by gsdwriter

October 31, 2013 at 12:05 pm

ISO Mounting Software

leave a comment »

If you are running Windows 8 then mounting ISO images is built in.

If you are running an earlier Windows version then you need software.  The simplest I’ve found is Virtual CloneDrive.  There are others that people seem to like, such as MagicISO and DaemonTools, but you aren’t supposed to install their free versions for commercial use, but Virtual CloneDrive is completely free and works great.

BTW: Don’t even think of using Microsoft’s Virtual CDRom Control Panel – it works on XP, but not on anything later without jumping through so many hoops that your legs will give way.

Written by gsdwriter

July 1, 2013 at 2:22 pm

Posted in Tools

Dev Humor: Apple’s next connector?

leave a comment »

Martin Fowler is a cool guy and I love his sense of humor:  Apple’s next connector?

If you don’t get which song the “next connector” name is coming from, then watch the video below:

Written by gsdwriter

May 30, 2013 at 9:45 am

Posted in Humor

“Unable to attach to process. A debugger is already attached.” (VS 2010, Classic ASP)

with 2 comments

Situation:

A fellow developer was using Visual Studio 2010 SP1 to debug a classic ASP application.  He attempted to attach to the IIS process, w3wp.exe and received the error message: “Unable to attach to process. A debugger is already attached.”

Data:

He is running Windows 7, 32 bit. (But I reproduced the error on Win7 64 bit.)

He is using IIS 7.5.

Yesterday he installed IE 10 32 bit. (Yesterday I installed IE 10 64 bit.)

We looked in Process Explorer but no debugger was running that we could see.

We tried changing the “Attach to” type in the “Attach to Process” dialog, but it had no effect.

We tried all sorts of things but nothing made any difference.

I found this forum article:  Visual Studio 2010 debugger already attached classic ASP

I tried debugging the same ASP site by attaching to the IIS process, using VS 2012 and it worked perfectly.

Solution:

Use VS 2012 or revert from IE 10 for Win7 to IE 9.

 

My fellow developer is installing VS 2012. (I don’t know why he didn’t do it already – heck, it’s worth it just for that cool Dark Theme.)

I hope that helps anyone hitting this issue.

Written by gsdwriter

March 1, 2013 at 1:36 pm

Follow

Get every new post delivered to your Inbox.