In C-Sharp I have a Registrations
class which basically creates a list of Questions
items like this:
public partial class Registrations
{
public Registrations()
{
this.Questions = new HashSet<Questions>();
}
public int id { get; set; }
public virtual ICollection<Questions> Questions { get; set; }
}
My Questions
class has a field called Title
and it just gives the form field label.
public partial class Questions
{
public int id { get; set; }
public int registrationId { get; set; }
public string Title { get; set; }
public string Data { get; set; }
}
When a user creates a registration, he can add many questions with different titles. I want to check if a specific registration has a field with the title "City". I want to create a function in my Registrations class called hasCity
which will return a boolean
depending if the specific registration has that field.
public hasCity()
{
Questions city = new Questions();
city.Title = "City";
if( this.Questions.Contains( city ) )
{
return true;
}
return false;
}
Now, the function above always returns false
and I am guessing it is because I need to create some kind of method to check only the Title
attribute for the string value City.