Home Can not add items to a list
Reply: 0

Can not add items to a list

user1407
1#
user1407 Published in May 21, 2018, 12:51 pm

I'm having problems at adding items to a list, following is my code:

using (var poolDbContext = new PoolContext())
{
    Question Q = new Question();
    Q.Text = "O triunfo do FC Porto frente ao Benfica arrumou de vez as contas do título?";
    Q.Answer.Add ="Sim, o FC Porto vai ser campeão.");


    Q.Answer.Add('Sim, o FC Porto vai ser campeão');
    Q.Answer.Add("Não, o Benfica ainda tem uma palavra a dizer.");
    Q.Answer.Add("Não, o Sporting ainda vai ser campeão.");
    Q.Answer.Add("Não ligo a futebol.");
    poolDbContext.Questions.Add(Q);
    poolDbContext.Answers.Add(Q);
    var count = poolDbContext.SaveChanges();
}

And here is my .Models.Questions:

public class Question
{
    public string Text { get; set; }
    public List<Answer> Answer { get; set; }

}

I'd like it to receive on the Models.Question the questions and the 4 answers for that questions. Please tell me if I'm doing something wrong.

Edit:

Here is the Answer-class:

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace PoolManager.Models 
{ 
    public class Answer 
    { 
        public string Questions { get; set; } 
        public string Answers { get; set; } 
        public string Results { get; set; } 
    } 
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.544071 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO