I'm testing LiteDB database but have an issue on updating a data. Let's consider the source code:
public class Session
{
[BsonId]
public int Id { get; set; }
public Guid SessionGuid { get; set; }
public DateTime Date { get; set; }
public double TotalAmount { get; set; }
[BsonRef("paymentInfos")]
public PaymentInfo PaymentInfos { get; set; }
}
public class PaymentInfo
{
[BsonId]
public int Id { get; set; }
public string Type { get; set; }
public double Amount { get; set; }
}
_database = new LiteDatabase(databasePath);
var sessions = _database.GetCollection<Session>("sessions");
var sessionId = Guid.NewGuid();
var session = new Session
{
SessionGuid = sessionId,
Date = Datetime.Now
};
sessions.Insert(session);
var sessions = _database.GetCollection<Session>("sessions");
var session = sessions.FindOne(x => x.SessionGuid == sessionId);
var paymentInfo = new PaymentInfo
{
Type = "Coin",
Amount = 2.0,
};
var paymentInfos = _database.GetCollection<PaymentInfo>("paymentInfos");
paymentInfos.Insert(paymentInfo);
session.PaymentInfos = paymentInfo;
sessions.Update(session);
session = sessions.FindOne(x => x.SessionGuid == sessionId);
var paymentAmount = session.PaymentInfos.Amount;
I was expecting that the paymentAmount will be 2.0, but it is only 0. It's like only the session.PaymentInfos.Id is good but all other properties have been lost. Is something wrong with my session update ? Maybe I've missed something ?
Thanks in advance.