0

I use his code for executing SQL query in entity framework :

using (var db = new VSServicesEntities()) { const string selectCmd = @"if exists (Select top 1 IsUserOn From ServiceMembers Where ServiceCode=@ServiceCode and Number=@Number) Select isnull(IsUserOn,0) IsON From ServiceMembers Where ServiceCode=@ServiceCode and Number=@Number else Select Null IsON"; var data = db.ServiceMembers.SqlQuery(selectCmd, number, serviceCode).ToList(); if (data.Count()>1) { //How to acccess value of returned column named IsON } 

and i want in the if block if (data.Count()>1) to access value of column that returned by executing query, this column's name is IsON, how can i access to it?

    1 Answer 1

    1

    If you are expecting a list of entities, then you will need to determine which one you want with .First(), .Single() or a similar function.

    From there it should be a simple case of writing var result = data.First().IsON; to get your value from that column, or something similar. This is the way I do it, you will get an exception if the entity isn't known or the column from the table isn't known either. But from what you have provided, it shouldn't be an issue.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.