views:

49

answers:

1

I've one interface which has following method signatures:

public interface ITag
{
    int M_Id { get; set; }
    string M_Name { get; set; }
}

And I have a class that implements the interface above:

[Table(Name="News")]
public class NewsTag:ITag
{
    [Column(Name="id",isPrimaryKey = true)]
    public int M_Id
    {
        get; set;
    }

    [Column(Name = "name")]
    public string M_Name
    {
        get; set;
    }

    [Column(Name = "extraField")]
    public string M_ExtraField
    {
        get;
        set;
    }
}

And i want to retrieve the rows from my db and send them

public IQueryable<ITag> fGetNewsTags(int id)
{
    var result = from news in context.GetTable<NewsTag>()
                 where news.M_Id == id
                 select news;

    return (IQueryable<ITag>)result;
}

But the problem is that the casting(return (IQueryable)result;) i am trying to use isn't working even though NewsTag is the child class of ITag interface.

Any help would be appreciated.

+5  A: 

try following

public IQueryable<ITag> fGetNewsTags(int id)
{
    var result = from news in context.GetTable<NewsTag>()
                 where news.M_Id == id
                 select (ITag)news;

    return result;
}
User Friendly