I have 2 entities: TextDocument
and TextBit
, they have many-to-many relation:
public class TextBit
{
public int Id { get; set; }
public string Value { get; set; }
public List<TextDocument> TextDocuments { get; set; } = new List<TextDocument>();
}
public class TextDocument
{
public int Id { get; set; }
public string Name { get; set; }
public List<TextBit> TextBits { get; set; } = new List<TextBit>();
}
First I add some TextBit
entities to the context:
meContext.Database.EnsureDeleted();
meContext.Database.EnsureCreated();
TextBit tb1 = new TextBit() { Value = "name " };
TextBit tb2 = new TextBit() { Value = " Igor " };
TextBit tb3 = new TextBit() { Value = " Hello " };
TextBit tb4 = new TextBit() { Value = " is " };
TextBit tb5 = new TextBit() { Value = " my " };
meContext.AddRange(new TextBit[] { tb1, tb2, tb3, tb4, tb5 });
meContext.SaveChanges();
Then I create a TextDocument
Entity called "introduction" and add those TextBit
entities as relations (There can be many TextDocument
s, each combines different sets of TextBit
s in different order.):
TextDocument doc1 = new TextDocument() { Name = "Introduction" };
doc1.TextBits.AddRange(new TextBit[] { tb1, tb2, tb3, tb4});
meContext.Add(doc1);
meContext.SaveChanges();
The problem is, if I want to get sensible sentence out of this TextDocument
, i.e. a "Hello my name is Igor ", I have to preserve the TextBit order for every TextDocument-TextBit pair in the database. As I understand I have to add an extra column to the combined TextBitTextDocument
table to represent an order of each textbit in every textdocument, but how do I then access this column to sort the text bits?