views:

65

answers:

3

Hi i have a function that should return me a string but what is is doing is bringing me back the sql expression that i am using on the database what have i done wrong

 public static IQueryable XMLtoProcess(string strConnection)
    {
        Datalayer.HameserveDataContext db = new HameserveDataContext(strConnection);

        var xml = from x in db.JobImports
                  where x.Processed == false
                  select new { x.Content };
        return xml;

    }

this is the code sample

this is what i should be getting back

<PMZEDITRI TRI_TXNNO="11127" TRI_TXNSEQ="1" TRI_CODE="600" TRI_SUBTYPE="1" TRI_STATUS="Busy" TRI_CRDATE="2008-02-25T00:00:00.0000000-00:00" TRI_CRTIME="54540" TRI_PRTIME="0" TRI_BATCH="" TRI_REF="" TRI_CPY="main" C1="DEPL" C2="007311856/001" C3="14:55" C4="CUB2201" C5="MR WILLIAM HOGG" C6="CS12085393" C7="CS" C8="Blocked drain" C9="Scheme: CIS Home Rescue edi tests" C10="MR WILLIAM HOGG" C11="74 CROMARTY" C12="OUSTON" C13="CHESTER LE STREET" C14="COUNTY DURHAM" C15="" C16="DH2 1JY" C17="" C18="" C19="" C20="" C21="CIS" C22="0018586965 ||" C23="BD" C24="W/DE/BD" C25="EX-DIRECTORY" C26="" C27="/" C28="CIS Home Rescue" C29="CIS Home Rescue Plus Insd" C30="Homeserve Claims Management Ltd|Upon successful completion of this repair the contractor must submit an itemised and costed Homeserve Claims Management Ltd Job Sheet." N1="79.9000" N2="68.0000" N3="11.9000" N4="0" N5="0" N6="0" D1="2008-02-25T00:00:00.0000000-00:00" T2="EX-DIRECTORY" T4="Blocked drain" TRI_SYSID="9" TRI_RETRY="3" TRI_RETRYTIME="0" />

can anyone help me please

A: 
  1. Your method is of type IQueryable
  2. You should not directly return xml; Convert it to return xml.ToList() or whatever you want it to be (In your case xml.ToString()
  3. Change your method type to String

If you directly return xml it'll be of type IQueryable

Prashant
i have tried this and im still getting the expression comming back to me
kevinw
instead of selecting new { x.Content }; try to select XElement.. I'm sure that you will the out you are expecting
Prashant
A: 

Maybe you need to force the query to be executed before returning the result, e.g. like this:

return xml.ToList();

This is necessary since your LINQ query is executed lazily, i.e. not until you actually access the result. Your code currently doesn't do this.

Konrad Rudolph
A: 

i have sorted it by using this

var xml = db.JobImports.Single(x => x.Processed == false);
return xml.Content;
kevinw