Inheritance

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a class name Article and another one named ArticleModel:

public class ArticleModel : Article { }

And the following:

IQueryable<ArticleModel> models = ArticleRepository.GetArticles();

GetArticles returns an IQueryable<Article> and I need to be to convert
it to IQueryable<ArticleModel>.

If possible in a linq expression. I would like to know how to do this.

Thanks,
Miguel
 
Hello,

I have a class name Article and another one named ArticleModel:

public class ArticleModel : Article { }

And the following:

 IQueryable<ArticleModel> models = ArticleRepository.GetArticles();

GetArticles returns an IQueryable<Article> and I need to be to convert
it to  IQueryable<ArticleModel>.

You might want to start with a simpler question. You have a single
Article, and you want to case it to ArticleModel. How?

The obvious answer: you can't. You have an instance of a base class.
It's not an instance of a derived class. There's nothing you can do to
make it one. You can, of course, make a new instance of derived class,
and copy properties of base (or maybe use a constructor the derived
class provides for that purpose), but that's about it.

Somehow I doubt that your question is what you actually need. What
exactly are you trying to do?
 
Back
Top