1

I'm working on a ASP.NET MVC project with Entity Framework, and I want to return value of one field from an database, and I won't to return full record, just value of one field.

This what I try :

    public JsonResult DUR_json(string FL)
    {
        var R = from F in DB_Context.Con.FLs where F.CODE_FL == FL select F.DUR_FL.First();


        return Json(new { DUR = R });
    }

But this code returns the full record, please any help ? Thanks in advance.

2 Answers 2

1

You need the bracets

Like this :

var R = (from F in DB_Context.Con.FLs where F.CODE_FL == FL select F.DUR_FL);

Wish this help.

Note : change the from Entity in the title to from database, this will help others to understand.

Sign up to request clarification or add additional context in comments.

Comments

1

Just select your field and then return first result:

var R = (from F in DB_Context.Con.FLs
         where F.CODE_FL == FL
         select F.DUR_FL).First();

Consider using FirstOrDefault() instead of First() if there might be no records with given CODE_FL

6 Comments

firstly thanks for your time, but bro I want just One Field exactly DUR_FL
DUR_FL is a navigation property according to your query F.DUR_FL.First() what type DUR_FL has?
didn't work bro, I got this error in the View : DbExpressionBinding requires an input expression with a collection ResultType. Parameter name: input
what type DUR_FL has?
DUR_FL is a field in database
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.