简体   繁体   中英

assign stored procedure result to list using Entity Framework

I'm using Entity Framework and what i want is to show stored procedure result into different labels like attribute News = lblnews.text and date = lblDate.text as far as i know i've to populate the result into list from stored procedure this is what i'm trying to do .. or if there is any other way please let me know

    dbContext = new OnlineDvdShopDBEntities();
    List<string> News = new List<string>();
    news = dbContext.spGetLatestNews();

i've search a lot on google but have no idea how to do.. my database is sending me a row of columns News Description and News Date that i want to store in particular labels..

The problem is that you are assigning results of stored procedure to list of strings, but result of that procedure is not list of strings. You can use var keyword to declare variable. The actual type will be inferred automatically:

var temp = dbContext.spGetLatestNews(); 
var firstNew = temp.FirstOrDefault();

if(firstNew != null)
{
    lblnews.Text = firstNew.NewDescription;
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM