Is it possible to use a cast operation for update expression in MongoDB C# drivers?

Viewed 17

I have this simple hierarchy:

public abstract class Foo 
{
    
}

public class Bar : Foo
{
    public bool Value { get; set; }
}

public class Container
{
    public Foo? Foo { get; set; }
}

I am trying to do the update like that:

Builders<Container>.Update.Set(x => ((Bar) x.Foo!).Value, true);

The update fails though:

MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: Convert(x.Foo, Bar).

I have a similar expression for projection and that one works with convert. I am not trying to do some conversion in the database here, but just to set in the expression to update one given field in a polymorphic object.

P.S. as fails with a similar error

0 Answers
Related