We’ve added a new column to a database table. The column is defined as follows:
Name: DisplayAsSoldOut
Type: Boolean
NOT NULLABLE
Default Value: 0
We’ve refreshed our EDMX data model and the new column appears just fine. We are on an ASP.NET 4.0 platform using C#.
We have a class defined as PagedList which inherits from List and implenents an interface IPagedList
Within the PagedList we have the following method:
protected void Initialize(IQueryable<T> source, int index, int pageSize, int? totalCount)
{
if (index < 0)
{ throw new ArgumentOutOfRangeException("PageIndex cannot be below 0."); }
if (pageSize < 1)
{ throw new ArgumentOutOfRangeException("PageSize cannot be less than 1."); }
if (source == null)
{ source = new List<T>().AsQueryable(); }
if (!totalCount.HasValue)
{ TotalItemCount = source.Count(); }
PageSize = pageSize;
PageIndex = index;
if (TotalItemCount > 0)
{ PageCount = (int)Math.Ceiling(TotalItemCount / (double)PageSize); }
else
{ PageCount = 0; }
HasPreviousPage = (PageIndex > 0);
HasNextPage = (PageIndex < (PageCount - 1));
IsFirstPage = (PageIndex <= 0);
IsLastPage = (PageIndex >= (PageCount - 1));
if (TotalItemCount > 0)
{ AddRange(source.Skip((index) * pageSize).Take(pageSize).ToList()); }
}
When we reach the following line:
{ AddRange(source.Skip((index) * pageSize).Take(pageSize).ToList()); }
we receive the following Exception …
Type: System.Data.EntityCommandExecutionException
Inner Exception: "Invalid column name 'DisplayAsSoldOut'."
I’ve tried searching for this type of exception but to no avail. The column appears in the EDMX dataset just fine. I even created a small throwaway program and imported the EDMX to do a simple read from the database and it worked fine. Has anyone run across something similar?
I apologize for the lengthy post but wanted to present as much info as I could.
I had a similar problem that was related to the edmx file being wrong needed fixing manually.
These files are a little hard to edit, so to figure out what was wrong I made a backup deleted and re-added the entire Model.edmx and Model.designer.cs
Then using good old winmerge I compared the two sets of files and figured out what was wrong. It was so esoteric I can’t actually remember the details, but I think it was an extra or a missing entry from one of the EDMX sections.