开发者

Shouldn't i cast Linq To Sql entity table to its real type?

When i call "f_CategoriNewsGet" function from Page_Load method I'm getting null. But i can see tblNewsler object is full with objects before return line.

protected void Page_Load(object sender, EventArgs e)
{
    var tblNewsler = News.f_CategoriNewsGet("ÇEVRE", 18); // return object is always
    Table<News> tblNewsler1 = tblNews;
    rptNatureNews.DataSource = tblNews != null ? tblNews.Take(6) : null;
    rptNatureNews.DataBind();
}

static public Table<News> f_CategoriNewsGet(string _sCategoriName, int _iTop)
{
    var tblNews = (from news in DAO.context.GetTable<News>()
                       join kategori in DAO.context.GetTab开发者_运维问答le<NewsCategori>() on                                news.M_RefNewsCategoriId equals kategori.M_NewsCategoriId
                       where kategori.M_Adi.Equals(_sCategoriName)
                       orderby news.M_InsertDate descending
                       select news).Take(_iTop);
    return tblNews as Table<News>;
}


tblNews is not a Table<News>. It is only an IQueryable<News>. context.GetTable<News> was a Table<News>, but applying query operators results in a different type -- the result of the query operator is no longer a Table<T>, but a (possibly internal) LINQ to SQL type representing the query.


You got a bug here:

Table<News> tblNewsler1 = tblNews;

Should Be

Table<News> tblNewsler1 =  tblNewsler;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜