You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use this Mongo.migration library, but I have a small problem with nullable properties in a complex model.
For example if I have a main model Person:
[RuntimeVersion("0.0.0")]
public class Person : IDocument
{
public Person(ObjectId id, string name, Partner? partner)
{
Id = id;
Name = name;
Partner = partner;
}
public ObjectId Id { get; }
public string Name { get; }
public Partner? Partner { get; }
public DocumentVersion Version { get; set; }
}
which contains the model Partner, which can be null. And which is also derived from IDocument and has the versions field like for example:
[RuntimeVersion("0.0.0")]
public class Partner : IDocument
{
public Partner(string name)
{
Name = name;
}
public string Name { get; }
public DocumentVersion Version { get; set; }
}
Now if I want to save a person with an empty partner, I get an Object reference not set to an instance of an Object.
This is because Mongo.Migration in the DocumentVersionService wants to write the version to the partner, which is not instantiated. In the case, if i save a person with an partner, it works fine...
In the DocumentVersionService on the method DetermineVersion I added a nullable check for the instance. If it's null, it will return without writing the Version on the instance, and if the instance is not null it will add the version as is. This works for me...
Now my question, is this in the sense of Mongo.migration, that each model in a complex model has his own version field,
or should I add this version field only on the main model (Person) and then interact in the up or down migration script through the BsonDocument.
The advantage, when every modal has his own version would be, that the up and down in the migration script will be much easer to handle.
thanks for your answer...
The text was updated successfully, but these errors were encountered:
Hi
I would like to use this Mongo.migration library, but I have a small problem with nullable properties in a complex model.
For example if I have a main model Person:
which contains the model Partner, which can be null. And which is also derived from IDocument and has the versions field like for example:
Now if I want to save a person with an empty partner, I get an Object reference not set to an instance of an Object.
This is because Mongo.Migration in the DocumentVersionService wants to write the version to the partner, which is not instantiated. In the case, if i save a person with an partner, it works fine...
In the DocumentVersionService on the method DetermineVersion I added a nullable check for the instance. If it's null, it will return without writing the Version on the instance, and if the instance is not null it will add the version as is. This works for me...
Now my question, is this in the sense of Mongo.migration, that each model in a complex model has his own version field,
or should I add this version field only on the main model (Person) and then interact in the up or down migration script through the BsonDocument.
The advantage, when every modal has his own version would be, that the up and down in the migration script will be much easer to handle.
thanks for your answer...
The text was updated successfully, but these errors were encountered: