Keep Order

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am getting a question and its answers (options) for a poll and
inserting into the database.

When I display the form I would like the answers to appear at the same
order as they were inserted.

However, this is not happening ... In fact every time I create a poll,
even with same answers, it seems its options are saved in some random
order.

Here is my code:

Leaf.Options = Leaf.OptionsCSV.Split(
new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries).Select(
o => new OptionLeaf {
Option = new Option {
OptionId = Guid.NewGuid(),
Answer = o.Trim(),
PollId = pollBook.Leaf.Poll.PollId,
}
}).ToList();

database.Options.InsertAllOnSubmit(Leaf.Options.Select(o =>
o.Option));

OptionsCSV is a string that contains the options inserted in an input.
For example:
Yes,No,Maybe

What is the best way to display the options using the same order as
they were inserted?

Thanks,
Miguel
 
Hello,

I am getting a question and its answers (options) for a poll and
inserting into the database.

When I display the form I would like the answers to appear at the same
order as they were inserted.

However, this is not happening ... In fact every time I create a poll,
even with same answers, it seems its options are saved in some random
order.

Here is my code:

      Leaf.Options = Leaf.OptionsCSV.Split(
        new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries).Select(
        o => new OptionLeaf {
          Option = new Option {
            OptionId = Guid.NewGuid(),
            Answer = o.Trim(),
            PollId = pollBook.Leaf.Poll.PollId,
          }
        }).ToList();

      database.Options.InsertAllOnSubmit(Leaf.Options.Select(o =>
o.Option));

OptionsCSV is a string that contains the options inserted in an input.
For example:
Yes,No,Maybe

What is the best way to display the options using the same order as
they were inserted?

Thanks,
Miguel

I tried to add a CreatedAt to each option:

pollBook.Leaf.Options = pollBook.Leaf.OptionsCSV.Split(
new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries).Select(
o => new OptionLeaf {
Option = new Option {
Answer = o.Trim(),
CreatedAt = DateTime.UtcNow,
OptionId = Guid.NewGuid(),
PollId = pollBook.Leaf.Poll.PollId,
}
}).ToList();
database.Options.InsertAllOnSubmit(pollBook.Leaf.Options.Select
(o => o.Option));
database.SubmitChanges();

When I debugged all options got the same DateTime. I checked the
ticks! So it won't help ...

And another strange thins is that when I went to the database, all
values were filled but not the datetime ...

Any idea?
 
I am getting a question and its answers (options) for a poll and
inserting into the database.
When I display the form I would like the answers to appear at the same
order as they were inserted.
However, this is not happening ... In fact every time I create a poll,
even with same answers, it seems its options are saved in some random
order.
Here is my code:
      Leaf.Options = Leaf.OptionsCSV.Split(
        new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries).Select(
        o => new OptionLeaf {
          Option = new Option {
            OptionId = Guid.NewGuid(),
            Answer = o.Trim(),
            PollId = pollBook.Leaf.Poll.PollId,
          }
        }).ToList();
      database.Options.InsertAllOnSubmit(Leaf.Options.Select(o =>
o.Option));
OptionsCSV is a string that contains the options inserted in an input.
For example:
Yes,No,Maybe
What is the best way to display the options using the same order as
they were inserted?
Thanks,
Miguel

I tried to add a CreatedAt to each option:

      pollBook.Leaf.Options = pollBook.Leaf.OptionsCSV.Split(
        new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries).Select(
        o => new OptionLeaf {
          Option = new Option {
            Answer = o.Trim(),
            CreatedAt = DateTime.UtcNow,
            OptionId = Guid.NewGuid(),
            PollId = pollBook.Leaf.Poll.PollId,
          }
        }).ToList();
      database.Options.InsertAllOnSubmit(pollBook.Leaf.Options.Select
(o => o.Option));
      database.SubmitChanges();

When I debugged all options got the same DateTime. I checked the
ticks! So it won't help ...

And another strange thins is that when I went to the database, all
values were filled but not the datetime ...

Any idea?

Please, anyone?

Thanks,
Miguel
 
Back
Top