0

I need to send a value to database this my code

var concerthallID = from _concert in db.tbl_Content_Context
    join _concerthall in db.tbl_Concert_ConcertHall on _concert.ContextID equals _concerthall.ContextID
    where _concert.EnContextID == concertid
    select _concerthall.ConcertHallID;

how to set ConcertHallID to a Variable?

3
  • Please give further information Commented Jun 2, 2015 at 20:26
  • I think i misunderstood the question do you mean you want to update the database or do you want to select the ID? Commented Jun 2, 2015 at 20:31
  • I want select a id and set the id value to a Variable Commented Jun 2, 2015 at 20:34

2 Answers 2

1

Your query will return an Iqueryable, so if it will return one row or you need the first one use this after your code:

var ID = concerthallID.FirstOrDefault();
Sign up to request clarification or add additional context in comments.

Comments

1

You'll need to select a single concert and select the id from it after making sure it is not null, the code should be something like this:

var concert = (from _concert in db.tbl_Content_Context
    join _concerthall in db.tbl_Concert_ConcertHall on _concert.ContextID equals _concerthall.ContextID
    where _concert.EnContextID == concertid
    select _concert).SingleOrDefault();

var concerthallID = 0;
if (concert !=null)
    concerthallID = concert.ConcertHallID;

Remember to surround this with a try catch block to make sure that the single is returning only one.

Comments

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.