0

I'm working with MVC3 C#.NET. I have a query that (up to now worked) which returns rows based off of the companyID:

var records = db.groupsToClassesMapping.Where(r => r.CompanyID == CompanyId);

The model looks like this:

[Table("Rpt_GroupsToClasses")]
public class GroupToClass
{
    public int id { get; set; }
    public string GroupName { get; set; }
    public string ClassName { get; set; }
    public int ClassIndex { get; set; }
    public int CompanyID { get; set; }
}

and the DBContext looks like this:

    public DbSet<GroupToClass> GroupsToClassesMapping { get; set; }

It used to be all of the table entries were filled, and the query would return results:

ID | Group Name | ClassName | ClassIndex | CompanyID
-----------------------------------------------------
1  | Pine       | Merch     | 1          | 1
2  | Oak        | Non-merch | 4          | 1

However, I find myself needing to have some of the entries blank:

ID | Group Name | ClassName | ClassIndex | CompanyID
-----------------------------------------------------
1  | Pine       | Merch     | 1          | 1
2  | Oak        | NULL      | NULL       | 1

and my query (where(r => r.companyID == CompanyId)) doesn't return anything. Is there something I need to do to the model fields to make this work right?

1 Answer 1

3

Make ClassIndex nullable by changing the datatype to int?.

Sign up to request clarification or add additional context in comments.

1 Comment

Ding ding ding. Thank you. I will accept this in exactly 9 minutes when SO deigns to let me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.