how to return 1 field (just 1 field) by Linq?

  • Thread starter Thread starter mesut
  • Start date Start date
M

mesut

Hi Colleagues,

I return Lists in my linq querys when I need to return a lot of rows
and fields etc.

But this time I only want to return 1 field... Input is a name of
BusinessUnit and output should be BusinessUnitGuid. both are in a
table called tblCostCenter.

But I don't know how to return 1 field... Can someone help with the
syntax?

- I don't even want the container busGuid (result of projection). so
can someone send me #2 correct syntax one with busGuid container and
return busGuid and another one w/o.

- but should be in field in in ?????????

my linqtable is called. costcenter and full namespace is :
Linq.Costcenter
table
Linq.CostCenter
fields
BusinessUnit type String
BusinessUnitGuid type Guid
Description type String
etc. etc. etc.

- why can't I put as return type Linq.Costcenter.BusinessUnitGuid as
function result parameter????


thanks,

mesut
//GetCostCenter - INPUT: BusinessUnit OUTPUT: BusinessUnitGUID


public ???????? GetBusinessUnitGuid(string businessUnit)
{
//connection to the Linq
objDataContext = DatabaseFactory.GetLinqConnection();

var busGuid= (from CostCenter in
objDataContext.tblCostCenters
where CostCenter.BusinessUnit ==
businessUnit
select CostCenter.BusinessUnitGuid);
return busGuid;

}
 
Mesut

Use the "new" statement in your select to define what column you want in
your var.

Cor
 
Hi Cor,

I did but no hope. But if I read well the instructions. if your return
1 field you don't need to use the "new". but maybe I'm wrong. anyway.
Do you have a sample LINQ query which returns a GUID (1 field) w/o
using a list()?

many thanks.
mesut


FYI: table in data context is called : Linq.tblCostCenters

public <What return type should be here???>
GetBusinessUnitGuid(string businessUnit)
{
//connection to the Linq
objDataContext = DatabaseFactory.GetLinqConnection();
var busGuid= (from CC in objDataContext.tblCostCenters
where CC.BusinessUnit == businessUnit
select CCr.BusinessUnitGuid);
return busGuid;
}
 
Back
Top