开发者

Return one record from my Model based on two parameters sent to my repository asp.net mvc 2

I pass two parameters to my repository to return one record

I am strugling to wite the code to return one record.

Here is my repository-

  public Classifieds_Ads GetUserClassifiedDetailsToModify(int classifiedid, Guid UserGuid)
        {
            return context.Classifieds_Ads.Where(c => c.User.Id == UserGuid && c => c.CatID == classifiedid);        
        }

I think you guys can see what I am trying to do but I just write the code. Can I have some help please!

It annoying because I know I will be licking mt self when i see the soloution.

I am 开发者_开发问答also using a stroingly typed views.

Thanks,


Try this:

public Classifieds_Ads GetUserClassifiedDetailsToModify(int classifiedid, Guid UserGuid)
{
    return context.Classifieds_Ads.Where(c => c.User.Id == UserGuid && c.CatID == classifiedid).First();        
}

If your data is returning more than one row you could ask it to return the first row by using the First extension method:

Where(c => c.User.Id == UserGuid && c.CatID == classifiedid).First()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜