5

I have classes

[MongoDiscriminated] public abstract class Content { public int? Id { get; set; } public int? ParentId { get; set; } public string Slug { get; set; } public string Path { get; set; } public string Title { get; set; } } public class Area : Content { } 

Query like this works

var item = mongo.GetCollection<Area>().AsQueryable().FirstOrDefault(); 

But when I make a query like

var item = mongo.GetCollection<Content>().AsQueryable().FirstOrDefault(); 

I get an InvalidCastException

Object must implement IConvertible. 

What's wrong? It shouldn't be a problem to convert Area to Content. Do I really have to make Content to implement IConvertible?

2 Answers 2

0

You could just cast it after the query:

mongo.GetCollection<Area>().AsQueryable().Cast<Content>().FirstOrDefault() 
Sign up to request clarification or add additional context in comments.

Comments

0

Just submitted a pull request on github to fix this exception:

https://github.com/atheken/NoRM/pulls

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.