I had a similar issue with a sql_variant column.
sql_variant is not supported in LINQ to SQL / EF, hence a trick is needed to get the query generated with a CAST(column as your_desired_type) otherwise LINQ to SQL will throw an exception Unable to cast object of type 'System.Int32' to type '%your desired type%'.
So, first define the column in your model with type object (instead of e.g. string)
[System.Data.Linq.Mapping.Table]
public class CompanyDimensionValue
{
// type "object" + private setter because Linq to SQL cannot map sql_variant
[System.Data.Linq.Mapping.Column]
public object Code { get; private set; }
}
and secondly add a System.Convert.ToString() to the query:
from v in table select
System.Convert.ToString(v.Code) // <- this generates a CAST(... as nvarchar...)