-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type is not a valid type to map #347
Comments
Currently you can't specify an interface on the I haven't otherwise done a ton of testing how interfaces would behave through MongoFramework and the driver, particularly around discriminators (the |
ok great I had a play around with this and saving to a One sticking point is when querying the |
This is another case of "kinda". If you were lookkng for a specific type, you can use This kinda deserialization control is basically what the MongoDB driver gives us. Under certain other situations, I do hijack it a bit to make it smarter (see the section in the readme about runtime type discovery) but outside of that, it is whatever the driver does. In theory, I could try and hijack it further to use similar smartness to directly do what you're suggesting on an entity by entity basis but that's gonna take a lot of digging into. |
Yes indeed I've witnessed this weirdness too though |
Unfortunately not, the This conversation though is making me think I could do a broader implementation of runtime type discovery and then I can apply it in exactly the case you're describing. I won't be able to do any work on this for at least a few weeks but it definitely is an interesting concept. |
I will look forward to trying it out. One other scenario I've just stumbled across is when the common base is a property and not the parent MongoDbSet type. How do you specify the required type in this situation? |
Ok I got around this by annotating the types to give the mongo driver a bit of guidance. It's a bit messy but does the job. This didn't work when I was using interfaces. [BsonDiscriminator(RootClass = true)]
[BsonKnownTypes(typeof(InheritorTypeA), typeof(InheritorTypeB))]
class BaseType { }
[BsonDiscriminator(nameof(InheritorA))]
class InheritorTypeA : BaseType { } |
If the mongo db set type is an interface i.e.
MongoDbSet<IMyInterfaceType>
it throws an error.Is there an example of how I can set this up? Some of my collection types are concrete though have properties that are interface types.
The text was updated successfully, but these errors were encountered: