question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type is not a valid type to map

See original GitHub issue

If the mongo db set type is an interface i.e. MongoDbSet<IMyInterfaceType> it throws an error.

Type is not a valid type to map (Parameter 'entityType')

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.

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Turnerjcommented, Apr 13, 2023

This is another case of “kinda”. If you were lookkng for a specific type, you can use OfType<YourInheritedType>() on your LINQ query to get it. It can have some weirdness still but you’ll be hitting more edge cases of the driver itself.

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.

1reaction
Turnerjcommented, Apr 7, 2023

Currently you can’t specify an interface on the MongoDbSet but you can use a shared base class if there are common properties you want across multiple types.

I haven’t otherwise done a ton of testing how interfaces would behave through MongoFramework and the driver, particularly around discriminators (the _t property in the document).

Read more comments on GitHub >

github_iconTop Results From Across the Web

'std::map' : 'SomeClass' is not a valid template type ...
I currently have a class that looks like the following . #define SET_METHOD( t , n ) \ private: t n; \ public:...
Read more >
all map elements must have the same type · Issue #21384 · ...
This default value is not compatible with the variable's type constraint: element ["a"]: all map elements must have the same type.
Read more >
Type Constraints - Configuration Language | Terraform
Within the Terraform language, they are only valid in the type argument ... Terraform does not provide any way to directly represent lists,...
Read more >
ERROR map of any single type required : r/Terraform
The error is saying it doesn't know what type the map is, so you need to define the type. Upvote 2
Read more >
Mastering TypeScript mapped types
In this post, we'll cover mapped types in TypeScript, a real-world example of them, and utility types including Partial, Readonly, and Pick.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found