Q:

LinQ Query Where Condition

I am trying to import data into a new database, but some of the columns in the old database are null.
In one of my methods, I am using the query below to get the records, like I said already there is a column in the rows which has a null value for some records.
Guid nameGuid= new guid('CCECE54B-EE14-4463-8A0B-02C72679334A')

MySubQuery = from a in MainQuery
              where a.Table1.Id.Equals(nameGuid)
        Select a;

I want to check for a.Table1.Id value, if it is equal to null, then I still want the row but ignore the where condition.
Any suggestion for using the ternary operator in Linq query or any other approaches for my task.

A:

Sounds like you want:
MySubQuery = from a in MainQuery
             where a.TableId.Id Is Nothing OrElse a.Table1.Id.Equals(nameGuid)

That's assuming my VB is correct... in C# I'd just write:
var query = from a in mainQuery
            where a.TableId.Id == null || a.TableId.Id == nameGuid
            select a;

or using the extension method directly:
var query = mainQuery.Where(a => a.TableId.Id == null || 
                                 a.TableId.Id == nameGuid);

