Friday, October 24, 2014 Register   Login

This site uses DNS Made Easy. Use it for reliable and professional DNS services.

RSS Feeds
Blog

Entries for April 2011

Apr
27

I've been working a lot more with LINQ2SQL and LINQ2Entities lately, and I ran into my first issue at the end of last week. I couldn't figure out why null parameters were causing the query to return strange results.

The original query looked like this:

   List<MenuLayoutDataEntity> ret = (from c in _Context.tblMenuLayouts
                                     where c.ConceptID == entity.ConceptID
                                     && c.ItemID == entity.ItemID
                                     && c.MarketID == entity.MarketID
                                     && c.DepartmentID == entity.DepartmentID
                                     orderby c.SortOrder
                                     select new MenuLayoutDataEntity()
                                     {
                                         MenuID = c.MenuID,
                                         ItemNamePOS = c.ItemNamePOS,
                                         ItemID = c.ItemID.HasValue ? c.ItemID.Value : -1
                                     }).ToList();

Sometimes, the MarketID and DepartmentID would be null, and that's what was causing the problem. After some Googling, I found that I need to enclose the equality using the Equals method in the object class. Here's the query using Equals:

 
   List<MenuLayoutDataEntity> ret = (from c in _Context.tblMenuLayouts
                                     where c.ConceptID == entity.ConceptID
                                     && c.ItemID == entity.ItemID
                                     && Equals(c.MarketID, entity.MarketID)
                                     && Equals(c.DepartmentID, entity.DepartmentID)
                                     orderby c.SortOrder
                                     select new MenuLayoutDataEntity()
                                     {
                                         MenuID = c.MenuID,
                                         ItemNamePOS = c.ItemNamePOS,
                                         ItemID = c.ItemID.HasValue ? c.ItemID.Value : -1
                                     }).ToList();

Unfortunately, this only works for LINQ2SQL, and this query is actually a LINQ2Entities query. So back to Googling. I finally found a hint in a post over at StackOverflow. Apparently, there's is a bug in the LINQ2Entities parser when trying to use IS NULL functionality in the where clause. The solution was to check the value on the entity class, and then select a specific query. Here's the results that actually gave me the results that I wanted:

 
            List<MenuLayoutDataEntity> ret = null;
 
            // Check if this is a store item, i.e. Departmental
            if (entity.MarketID.HasValue && entity.DepartmentID.HasValue)
            {
                ret = (from c in _Context.tblMenuLayouts
                       where c.ConceptID == entity.ConceptID
                             && c.ItemID == entity.ItemID
                             && c.MarketID == entity.MarketID
                             && c.DepartmentID == entity.DepartmentID
                       orderby c.SortOrder
                       select new MenuLayoutDataEntity()
                       {
                           MenuID = c.MenuID,
                           ItemNamePOS = c.ItemNamePOS,
                           ItemID = c.ItemID.HasValue ? c.ItemID.Value : -1
                       }).Distinct().ToList();
            }
 
            // Check if this is a market item, i.e. MarketID is not null
            if (entity.MarketID.HasValue && !entity.DepartmentID.HasValue)
            {
                ret = (from c in _Context.tblMenuLayouts
                       where c.ConceptID == entity.ConceptID
                             && c.ItemID == entity.ItemID
                             && c.MarketID == entity.MarketID
                             && c.DepartmentID == null
                       orderby c.SortOrder
                       select new MenuLayoutDataEntity()
                       {
                           MenuID = c.MenuID,
                           ItemNamePOS = c.ItemNamePOS,
                           ItemID = c.ItemID.HasValue ? c.ItemID.Value : -1
                       }).Distinct().ToList();
            }
 
            // Check if this is a global item, i.e. both MarketID and DepartmentID are null
            if (!entity.MarketID.HasValue && !entity.DepartmentID.HasValue)
            {
                ret = (from c in _Context.tblMenuLayouts
                       where c.ConceptID == entity.ConceptID
                             && c.ItemID == entity.ItemID
                             && c.MarketID == null
                             && c.DepartmentID == null
                       orderby c.SortOrder
                       select new MenuLayoutDataEntity()
                       {
                           MenuID = c.MenuID,
                           ItemNamePOS = c.ItemNamePOS,
                           ItemID = c.ItemID.HasValue ? c.ItemID.Value : -1
                       }).Distinct().ToList();
            }

Very annoying, but at least I know how to handle this. Hopefully this will help another soul out there.

posted @ Wednesday, April 27, 2011 11:32 AM by Hector Sosa, Jr

Posted in: Code, Databases

Actions: Tweet This  Share on Facebook  Share on LinkedIn  Emakl  Permalink  del.icio.us
Apr
10
 3873 Views ::  6 Comments RSS comment feed

I was in the process of updating both PainlessSVN Professional and Console to version 1.2.1, when I found a bug in Visual Studio 2010 debugger. The solutions for both projects were in VS2008. My OS recently died, so I had to re-install it from scratch. I only installed VS2010, because I wanted to move away from VS2008.

My first hint that something was wrong was when I needed to modify the About dll to include the new version numbers and years in the copyright. This project is a C++ resource dll. This simple project would not compile on the VS2010 compiler when I converted it. I ended up firing one of my VMWare images that has VS2008 to get this done.

The next thing that happened was that none of the breakpoints I set worked, while trying to track down an unhandled exception. I went to Google and found that this is a known bug. The report is over here:

Debugging an MMC snapin does not attach correctly to mmc.exe

The suggested work around is here:

Can’t hit breakpoints in a plug-in or can’t debug .NET 2.0/3.0/3.5 from a mixed mode .exe project with Visual Studio 2010?

Unfortunately, that didn't work for me. What did work was to change the mmc.exe instance from the C:\Windows\SysWow64 to the one in C:\Windows\System32, then attach the debugger manually. The debugger will not attach to instances of the mmc.exe program in the SysWow64 directory. I am running VS2010 on Windows 7 Ultimate x64, and that's why I was using the 64 bit version of mmc.exe.

Anyways, hope this helps somebody else.

posted @ Sunday, April 10, 2011 10:16 PM by Hector Sosa, Jr

Actions: Tweet This  Share on Facebook  Share on LinkedIn  Emakl  Permalink  del.icio.us
Apr
09

A TextFileSplitter user commented that the UI is too big on his screen. I added accelerators to the Split! and Get Command Line buttons. Not sure why I didn't add these before.

NEW - Added accelerator to the Split! button. It is ALT-S.
NEW - Added accelerator to the Get Command Line button. It is ALT-G.

You can download it HERE.

posted @ Saturday, April 09, 2011 2:58 PM by Hector Sosa, Jr

Actions: Tweet This  Share on Facebook  Share on LinkedIn  Emakl  Permalink  del.icio.us
  
Terms Of Use | Privacy Statement | SystemWidgets
Copyright 2002-2014 by SystemWidgets
Google Analytics Alternative