0

Upgrading from Asp.Net 2.1 to 3.1 I am getting errors on a number of routines that select data with the error ArgumentNullException: Value cannot be null. (Parameter 'source')

The following worked fine in 2.1 but produces this error in 3.1:

Lines = _context.DirectoryYearPageLinesInfo.Where(p => p.LName.ToLower() == sLName.ToLower()).Distinct().ToList();

This was producing the above error, so I tried Sql:

Lines = _context.DirectoryYearPageLinesInfo.FromSqlRaw("SELECT DISTINCT * FROM dbo.DirectoryYearPageLinesInfo WHERE LOWER(LName) = '" + sLName + "'").ToList();

Same error. Lines is defined as:

IEnumerable<DirectoryYearPageLineInfo> Lines = new List<DirectoryYearPageLineInfo>();

DirectoryYearPageLineInfo as:

public class DirectoryYearPageLineInfo
{
    [Key]
    [DisplayName("Directory Year")]
    public string DirectoryYear { get; set; }

    [Key]
    [DisplayName("Directory Page")]
    public Nullable<int> DirectoryPage { get; set; }

    [Key]
    [DisplayName("Directory Line")]
    public Nullable<int> DirectoryLine { get; set; }

    [Key]
    public int AddressId { get; set; }
    public string Title { get; set; }

    [DisplayName("First Name(s)")]
    public string FName { get; set; }

    [DisplayName("Last Name(s)")]
    public string LName { get; set; }...

The context file:

modelBuilder.Entity<DirectoryYearPageLineInfo>()
            .HasKey(d => new {d.DirectoryYear, d.DirectoryPage, d.DirectoryLine, d.AddressId });

I've tried various things like turning it into a IQueryable, removing Lower, etc., but it always produces the same error. I feel that there is something I'm missing in the conversion.

Richard Deeming
  • 29,830
  • 10
  • 79
  • 151

0 Answers0