Pass parameters to linq queries - c#

I have the following part of code that works perfectly.
public Task<List<RsvItemsViewModel>> GetReservations(int company_ID)
{
try
{
// we cannot pass parameter as company_id . we use hard coded values as 1 for CompanyId.Must find a way to overcome this
return ((from a in gTravelDbContext.Set<Frsvitem>()
join d in gTravelDbContext.Set<Freserv>()
on a.Rsinum equals d.Rsvnum into gd from d in gd.Where(p1 => p1.CompanyId == 1)
join c in gTravelDbContext.Set<Fsupplier>()
on a.SupplId equals c.SupplId into gc from c in gc.Where(p1=>p1.CompanyId == 1)
join i in gTravelDbContext.Set<Fzone>()
on a.Rsizone equals i.Zoneid into gi
from i in gi.DefaultIfEmpty() where i.CompanyId == 1
join g in gTravelDbContext.Set<Fservtype>()
on a.Rsisertype equals g.Stypecode
join b in gTravelDbContext.Set<Fcustomer>()
on d.CustId equals b.CustId
join e in gTravelDbContext.Set<Fpaykind>()
on d.Rsvpaymethod equals e.Payid into ge
from e in ge.DefaultIfEmpty()
join f in gTravelDbContext.Set<Fsalesman>()
on d.Rsvsalescode equals f.Salescode into gf
from f in gf.DefaultIfEmpty()
join h in gTravelDbContext.Set<Fpinake>()
on d.Rsvakirosi equals h.Tblid into gh
from h in gh.Where(p => p.Tblcd == "yesno")
select new RsvItemsViewModel
{
Rsinum = a.Rsinum,
Stypename = g.Stypename,
Cuname = b.Cuname,
Rsvcuname = d.Rsvcuname,
Sumame = c.Suname,
Rsvakirosi = d.Rsvakirosi,
Yesno = h.Tbltext ,
Paytext = e.Paytext,
Salesname = f.Salesname,
Stypegroup = g.Stypegroup,
Company_id =d.CompanyId.GetValueOrDefault(),
Zonename = i.Zonename,
Rsisertype = a.Rsisertype,
Suppl_id = a.SupplId,
Xrhsh = d.Xrhsh,
Bpar_id = a.BparId
}
).ToListAsync());
}
catch (Exception)
{
throw;
}
}
The problem is that I want to pass company_ID as a parameter in linq and I want to substitute the Where(p1 => p1.CompanyId == 1) with Where(p1 => p1.CompanyId == company_ID )
I would be grateful if someone could help me.
Thank you

You have used GroupJoin in way, which is not supported by EF Core. GroupJoin has a lot of limitations and use it only if you need LEFT JOIN.
I have rewritten your query to be translatable:
var query =
from a in gTravelDbContext.Set<Frsvitem>()
from d in gTravelDbContext.Set<Freserv>().Where(d => d.Rsvnum == a.Rsinum && d.CompanyId == company_ID)
from c in gTravelDbContext.Set<Fsupplier>().Where(c => a.SupplId == c.SupplId && c.CompanyId == company_ID)
from i in gTravelDbContext.Set<Fzone>().Where(i => a.Rsizone == i.Zoneid && c.CompanyId == company_ID).DefaultIfEmpty()
join g in gTravelDbContext.Set<Fservtype>()
on a.Rsisertype equals g.Stypecode
join b in gTravelDbContext.Set<Fcustomer>()
on d.CustId equals b.CustId
join e in gTravelDbContext.Set<Fpaykind>()
on d.Rsvpaymethod equals e.Payid into ge
from e in ge.DefaultIfEmpty()
join f in gTravelDbContext.Set<Fsalesman>()
on d.Rsvsalescode equals f.Salescode into gf
from f in gf.DefaultIfEmpty()
from h in gTravelDbContext.Set<Fpinake>().Where(h => d.Rsvakirosi == h.Tblid && h.Tblcd == "yesno")
select new RsvItemsViewModel
{
Rsinum = a.Rsinum,
Stypename = g.Stypename,
Cuname = b.Cuname,
Rsvcuname = d.Rsvcuname,
Sumame = c.Suname,
Rsvakirosi = d.Rsvakirosi,
Yesno = h.Tbltext ,
Paytext = e.Paytext,
Salesname = f.Salesname,
Stypegroup = g.Stypegroup,
Company_id =d.CompanyId.GetValueOrDefault(),
Zonename = i.Zonename,
Rsisertype = a.Rsisertype,
Suppl_id = a.SupplId,
Xrhsh = d.Xrhsh,
Bpar_id = a.BparId
}

Related

The specified LINQ expression contains references to queries that are associated with different contexts c#

I have this simple function that returns a query, but when I try to join 2 tables in different databases, the error raised: The specified LINQ expression contains references to queries that are associated with different contexts.
here is my code.
private object projectcycleFilter(int? pid, int? cid, int UserId)
{
string[] res = { null, "" };
int?[] resint = { null, 0 };
var access_user = (from p in geotagging.webpages_UsersInRoles join s in geotagging.UserProfiles on p.UserId equals s.UserId where p.UserId == UserId select p).ToList();
var x = new object();
var geotaggingquery = (from xx in geotagging.sub_project select xx).AsEnumerable();
var nfmsquery = (from p in nfmsdb.request_for_refund join lr in nfmsdb.lib_regions on p.region_code equals lr.region_code join lp in nfmsdb.lib_provinces on p.prov_code equals lp.prov_code join lc in nfmsdb.lib_cities on p.city_code equals lc.city_code join lb in nfmsdb.lib_brgy on p.brgy_code equals lb.brgy_code join gts in geotaggingquery on p.sub_project_id equals gts.sub_project_id select new { lb, lc, lp, lr, p, gts }).AsEnumerable();
if (access_user.Select(x => x.RoleId).FirstOrDefault() > 2)
{
nfmsquery = (from p in nfmsdb.request_for_refund join lr in nfmsdb.lib_regions on p.region_code equals lr.region_code join lp in nfmsdb.lib_provinces on p.prov_code equals lp.prov_code join lc in nfmsdb.lib_cities on p.city_code equals lc.city_code join lb in nfmsdb.lib_brgy on p.brgy_code equals lb.brgy_code join gt in nfmsdb.user_municipal_access on p.city_code equals gt.city_code join gts in geotaggingquery on p.sub_project_id equals gts.sub_project_id where gt.user_id == UserId && gt.selected == true select new { lb, lc, lp, lr, p, gts }).AsEnumerable();
}
if (!resint.Contains(pid))
{
nfmsquery = nfmsquery.Where(x => x.gts.project_type_id == pid);
}
if (!resint.Contains(cid))
{
nfmsquery = nfmsquery.Where(x => x.gts.cycle_id == cid);
}
var result = nfmsquery.Select(x => new
{
sub_project_id = x.p.sub_project_id,
sub_project_name = x.p.sub_project_name,
region_name = x.lr.region_name,
region_code = x.lr.region_code,
prov_name = x.lp.prov_name,
prov_code = x.lp.prov_code,
city_name = x.lc.city_name,
city_code = x.lc.city_code,
brgy_code = x.lb.brgy_code,
brgy_name = x.lb.brgy_name,
request_for_refund_id = x.p.request_for_refund_id,
total_sub_project_cost = x.p.total_sub_project_cost,
total_program_cost = x.p.total_program_cost,
region_director = x.p.region_director,
lbp_branch = x.p.lbp_branch,
address = x.p.address,
lcc_amount = x.p.lcc_amount,
account_name = x.p.account_name,
bank_no = x.p.bank_no,
amount_requested = x.p.amount_requested,
tranche_id = x.p.tranche_id,
prev_amount_release = x.p.prev_amount_release,
cumul_total_request = x.p.cumul_total_request,
date_created = x.p.date_created,
date_requested = x.p.date_requested,
brgy_chair_name = x.p.brgy_chair_name,
bspmc_name = x.p.bspmc_name,
ac_name = x.p.ac_name,
lprao_name = x.p.lprao_name,
lprao_date = x.p.lprao_date,
rpc_name = x.p.rpc_name,
rpm_name = x.p.rpm_name,
ac_date = x.p.ac_date,
rpc_date = x.p.rpc_date,
rpm_date = x.p.rpm_date,
updated_by = x.p.updated_by,
date_updated = x.p.date_updated,
isdeleted = x.p.isdeleted,
}).ToList();
return result;
}
I also try var geotaggingquery = (from xx in geotagging.sub_project select xx).ToList() and `var nfmsquery = (from p in nfmsdb.request_for_refund join lr in nfmsdb.lib_regions on p.region_code equals lr.region_code join lp in nfmsdb.lib_provinces on p.prov_code equals lp.prov_code join lc in nfmsdb.lib_cities on p.city_code equals lc.city_code join lb in nfmsdb.lib_brgy on p.brgy_code equals lb.brgy_code join gts in geotaggingquery on p.sub_project_id equals gts.sub_project_id select new { lb, lc, lp, lr, p, gts }).ToList();, nothing happens.
Thanks in advance

flatten out webapi EF using DTO and linq- using IF/THEN

I am attempting to flatten out my webapi EF using DTO's. So far I have the below statement working correctly. Now I want to add a layer of complexity stating a IF/THEN. I put a fake code in the first line of SELECT NEW SECTION.
Can someone please assist?
var query = (
from acctTbl in db.Accounts
join tradeTbl in db.Trades on acctTbl.AccountID equals tradeTbl.AccountID into ts
from tradeTbl in ts.DefaultIfEmpty()
join mapClientAcct in db.Mapping_ClientAccounts on acctTbl.AccountID equals mapClientAcct.AccountID
join clientTbl in db.Clients on mapClientAcct.ClientID equals clientTbl.ClientID
join mapUserClient in db.Mapping_UserClients on clientTbl.ClientID equals mapUserClient.ClientID
join aspNetUser in db.AspNetUsers on mapUserClient.AspNetUsersID equals aspNetUser.Id
join mktData in db.MarketDatas on tradeTbl.MarketDataID equals mktData.MarketDataID into ms
from mktData in ms.DefaultIfEmpty()
join mktCode in db.GMI_MarketCodes on tradeTbl.GMI_MarketCodesID equals mktCode.GMI_MarketCodesID into mc
from mktCode in mc.DefaultIfEmpty()
join Mgrs in db.Managers on acctTbl.ManagerID equals Mgrs.ManagerID
join FxMkts in db.ForexMarkets on mktData.crncy equals FxMkts.CurrencySymbol into fm
from FxMkts in fm.DefaultIfEmpty()
where acctTbl.AccountActive == true
&& clientTbl.ClientID == clientID
&& aspNetUser.UserName == username
select new TradeDetailDTO()
{
--THIS IS WHAT I WANT TO DO!!!
IF tradeTblIdentifier == "F" THEN 'yes'
ELSE 'no'
-------------------------
Filedate = tradeTbl.Filedate,
Quantity = tradeTbl.Quantity,
Month = tradeTbl.Month,
Strike = tradeTbl.Strike,
PutCall = tradeTbl.PutCall,
Prompt = tradeTbl.Prompt,
StmtPrice = tradeTbl.Price,
ShortDesc = mktCode.ShortDesc,
Sector = mktCode.Sector,
ExchName = mktCode.ExchName,
BBSymbol = mktData.BBSymbol,
BBName = mktData.Name,
fut_Val_Pt = mktData.fut_Val_Pt,
crncy = mktData.crncy,
fut_tick_size = mktData.fut_tick_size,
fut_tick_val = mktData.fut_tick_val,
fut_init_spec_ml = mktData.fut_init_spec_ml,
last_price = mktData.last_price,
bid = mktData.bid,
ask = mktData.ask,
px_settle_last_dt_rt = mktData.px_settle_last_dt_rt,
px_settle_actual_rt = mktData.px_settle_actual_rt,
chg_on_day = mktData.chg_on_day,
prev_close_value_realtime = mktData.prev_close_value_realtime,
AccountNumber = acctTbl.AccountNumber,
TradeLevel = acctTbl.TradeLevel,
ManagerName = Mgrs.ManagerName,
ManagerShortCode = Mgrs.ManagerShortCode,
ForexLastPrice = db.MarketDatas.FirstOrDefault(x => x.BBSymbol == mktData.crncy + " BGN CURNCY") == null ? 1: db.MarketDatas.FirstOrDefault(x => x.BBSymbol == mktData.crncy + " BGN CURNCY").last_price,
//ForexLastPrice = FxMkts.LastPrice, ORIGINAL
TopdayIdentifier = "P",
DailyPercentage = acctTbl.DailyPercentage,
AccountType = acctTbl.AccountType
}
);
If i understood you correctly you want something like this:
var query = (
from acctTbl in db.Accounts
join tradeTbl in db.Trades on acctTbl.AccountID equals tradeTbl.AccountID into ts
from tradeTbl in ts.DefaultIfEmpty()
join mapClientAcct in db.Mapping_ClientAccounts on acctTbl.AccountID equals mapClientAcct.AccountID
join clientTbl in db.Clients on mapClientAcct.ClientID equals clientTbl.ClientID
join mapUserClient in db.Mapping_UserClients on clientTbl.ClientID equals mapUserClient.ClientID
join aspNetUser in db.AspNetUsers on mapUserClient.AspNetUsersID equals aspNetUser.Id
join mktData in db.MarketDatas on tradeTbl.MarketDataID equals mktData.MarketDataID into ms
from mktData in ms.DefaultIfEmpty()
join mktCode in db.GMI_MarketCodes on tradeTbl.GMI_MarketCodesID equals mktCode.GMI_MarketCodesID into mc
from mktCode in mc.DefaultIfEmpty()
join Mgrs in db.Managers on acctTbl.ManagerID equals Mgrs.ManagerID
join FxMkts in db.ForexMarkets on mktData.crncy equals FxMkts.CurrencySymbol into fm
from FxMkts in fm.DefaultIfEmpty()
where acctTbl.AccountActive == true
&& clientTbl.ClientID == clientID
&& aspNetUser.UserName == username
select new TradeDetailDTO()
{
YesNo = tradeTbl.Identifier == "F"?"yes":"no",
Filedate = tradeTbl.Filedate,
Quantity = tradeTbl.Quantity,
Month = tradeTbl.Month,
Strike = tradeTbl.Strike,
PutCall = tradeTbl.PutCall,
Prompt = tradeTbl.Prompt,
StmtPrice = tradeTbl.Price,
ShortDesc = mktCode.ShortDesc,
Sector = mktCode.Sector,
ExchName = mktCode.ExchName,
BBSymbol = mktData.BBSymbol,
BBName = mktData.Name,
fut_Val_Pt = mktData.fut_Val_Pt,
crncy = mktData.crncy,
fut_tick_size = mktData.fut_tick_size,
fut_tick_val = mktData.fut_tick_val,
fut_init_spec_ml = mktData.fut_init_spec_ml,
last_price = mktData.last_price,
bid = mktData.bid,
ask = mktData.ask,
px_settle_last_dt_rt = mktData.px_settle_last_dt_rt,
px_settle_actual_rt = mktData.px_settle_actual_rt,
chg_on_day = mktData.chg_on_day,
prev_close_value_realtime = mktData.prev_close_value_realtime,
AccountNumber = acctTbl.AccountNumber,
TradeLevel = acctTbl.TradeLevel,
ManagerName = Mgrs.ManagerName,
ManagerShortCode = Mgrs.ManagerShortCode,
ForexLastPrice = db.MarketDatas.FirstOrDefault(x => x.BBSymbol == mktData.crncy + " BGN CURNCY") == null ? 1: db.MarketDatas.FirstOrDefault(x => x.BBSymbol == mktData.crncy + " BGN CURNCY").last_price,
//ForexLastPrice = FxMkts.LastPrice, ORIGINAL
TopdayIdentifier = "P",
DailyPercentage = acctTbl.DailyPercentage,
AccountType = acctTbl.AccountType
}
);

Primitive type error in LINQ to SQL query+subquery

I got the famous "only primitive types or enumeration types..." error, and I cannot find the solution.
This is the code that is making my head explode (it's part of a select in another LINQ code):
Min = (from inddetails in EntitiesDB.ConfSet
where (final.Max(x => x.hosp.Hos_NumOnc) > inddetails.Conf_Desde && final.Max(x => x.hosp.Hos_NumOnc) < inddetails.Conf_Hasta)
|| final.Max(x => x.hosp.Hos_NumOnc) > (from inddetails2 in EntitiesDB.ConfSet select inddetails2.Conf_Hasta).Max()
select inddetails.Conf_NumeroRegistros)
Here is the full code as requested with the last updates (nothing changed):
var result = from indicadores in EntitiesDB.Catalogo_IndicadoresSet
join crit in EntitiesDB.Catalogo_CriteriosSet on indicadores.CodigoCriterio equals crit.CodigoCriterio
join dimen in EntitiesDB.Catalogo_DimensionSet on crit.CodigoDimension equals dimen.CodigoDimension
join grupo in EntitiesDB.Catalogo_GruposSet on dimen.CodigoGrupo equals grupo.CodigoGrupo
join indicador_resultado in EntitiesDB.Catalogo_Indicador_ResultadoSet.DefaultIfEmpty() on indicadores.CodigoIndicador equals indicador_resultado.CodigoIndicador /*into joined
from j in joined.DefaultIfEmpty()*/
join user in EntitiesDB.UsuariosSet on indicador_resultado.CodigoUsuario equals user.CodigoUsuario
join hosp in EntitiesDB.HospitalesSet on user.CodigoHospital equals hosp.CodigoHospital
join hosper in EntitiesDB.Rel_Hospital_PeriodoSet on hosp.CodigoHospital equals hosper.CodigoHospital
join period in EntitiesDB.PeriodosSet on hosper.CodigoPeriodo equals period.CodigoPeriodo
where period.CodigoPeriodo == periodos.CodigoPeriodo
group new { indicadores, hosper, hosp, grupo, crit, dimen, indicador_resultado, user, period } by new { hosper.CodigoPeriodo, hosp.CodigoHospital, grupo.CodigoGrupo, indicadores.CodigoIndicador, period.Per_Nombre, hosp.Hos_Nombre, hosp.Hos_NumeroOncologos, grupo.Gru_Descripcion, indicador_resultado.CodigoResultado, indicador_resultado.Resul_Completado, indicador_resultado.Resul_Numerador, indicador_resultado.Resul_Denominador, indicador_resultado.Resul_Valor, indicador_resultado.Resul_Objetivo, indicador_resultado.Resul_Variacion, indicador_resultado.Resul_Detalle, indicador_resultado.Resul_Fecha, indicadores.Ind_Descripcion, dimen.CodigoDimension, crit.CodigoCriterio } into final
orderby final.Key.CodigoPeriodo, final.Key.CodigoHospital, final.Key.CodigoGrupo
select new
{
CodigoPeriodo = final.Key.CodigoPeriodo,
NombrePeriodo = final.Key.Per_Nombre,
CodigoHospital = final.Key.CodigoHospital,
NombreHospital = final.Key.Hos_Nombre,
NumeroOncologos = final.Key.Hos_NumeroOncologos),
CodigoGrupo = final.Key.CodigoGrupo,
NombreGrupo = final.Key.Gru_Descripcion,
CodigoResultado = final.Max(x => x.indicador_resultado.CodigoResultado),
Completado = final.Key.Resul_Completado,
Numerador = final.Max(x => x.indicador_resultado.Resul_Numerador),
Denominador = final.Max(x => x.indicador_resultado.Resul_Denominador),
Valor = final.Max(x => x.indicador_resultado.Resul_Valor),
Objetivo = final.Max(x => x.indicador_resultado.Resul_Objetivo),
Variacion = final.Max(x => x.indicador_resultado.Resul_Variacion),
Detalle = final.Key.Resul_Detalle,
CodigoIndicador = final.Key.CodigoIndicador,
NombreIndicador = final.Key.Ind_Descripcion,
CodigoDimension = final.Max(x => x.dimen.CodigoDimension),
CodigoCriterio = final.Max(x => x.crit.CodigoCriterio),
CasosMinimos = (from inddetalle in EntitiesDB.Configuracion_IndicadoresDetalleSet
where (final.Key.Hos_NumeroOncologos > inddetalle.Conf_Desde && final.Key.Hos_NumeroOncologos < inddetalle.Conf_Hasta)
|| final.Key.Hos_NumeroOncologos) > valorMaximo
select inddetalle.Conf_NumeroRegistros)
};
Take the max value out of the query:
var finalMax = final.Max(x => x.hosp.Hos_NumOnc);
Min = (from inddetails in EntitiesDB.ConfSet
where (finalMax > inddetails.Conf_Desde
&& finalMax < inddetails.Conf_Hasta)
|| finalMax > (from inddetails2 in EntitiesDB.ConfSet select inddetails2.Conf_Hasta).Max()
select inddetails.Conf_NumeroRegistros);
final is a collection of (non-primitive) objects, for which there is no SQL equivalent. It's also more efficient to do it this way.

Several actions were found that match request - webapi anonymous type+function

I'm returning anonymouse type from my webapi controller, one of the values I need to be computed by using function. When I'm trying to do this way getting error say "Several actions were found that match request".
Here is how I call GET:
// GET api/Grafik/5
public IHttpActionResult GetGrafik(int id)
{
xTourist t = db.xTourist.Find(id);
var beach = db.xAdres.Find(t.Hotel).Kod;
var result = from a in db.Grafik
join b in db.Excursions on a.Excursion equals b.Kod
join c in db.Dates on a.KodD equals c.KodD
join d in db.Staff on a.Guide equals d.Kod
where c.Date > t.ArrDate && c.Дата < t.DepDate
let pu = from x in db.xPickUp where x.KodP == beach && x.Excursion == b.Kod select x.PickUpTime
orderby c.Date
select new { kodg = a.Kodg, excursion = b.Name, guide = d.GuideName, data = c.Date, pricead = b.Price,
pricech = b.PriceChd, pax = t.Pax, child = t.Ch, paxleft = GetPax(a.Kodg), pickup = pu.FirstOrDefault()};
return Ok(result);
}
And here is the function returning needed value:
public int GetPax(int id)
{
//get pax quota
var pre = db.Grafik.Where(k => k.Kodg == id).Select(p => p.Quota).SingleOrDefault();
if (pre.HasValue && pre.Value > 0)
{
//Get taken pax
var p = (from a in db.Orders where a.Kodg == id & !(a.Cansel == true) select a.Child).Sum();
var c = (from a in db.Orders where a.Kodg == id & !(a.Cansel == true) select a.Pax).Sum();
if (p.HasValue & c.HasValue)
{
return pre.Value - (p.Value + c.Value);
}
else
{
return pre.Value;
}
}
else
{
return 0;
}
}
Web API is seeing two public methods with id as a parameter and it can't figure out which one to execute when you send your request. Looking at your code, there's no need for the helper method GetPax() to be public. Try changing it to private.
private int GetPax(int id) // ...
I found solution. Ok, this could be a bit strange way, but it's working.
public IHttpActionResult GetГрафик(int id)
{
xTourist t = db.xTourist.Find(id);
var beach = db.xAdres.Find(t.Hotel).Kod;
var result = from a in db.Grafik
join b in db.Excursions on a.Excursion equals b.Kod
join c in db.Dates on a.Kodd equals c.Kodd
join d in db.Staff on a.Guidename equals d.Kod
join e in db.Заказы on a.КодГ equals e.КодГ
where c.Дата > t.Датапр && c.Дата < t.Датаотл
let pu = from x in db.xPickUp where x.КодП == beach && x.Excursion == b.Kod select x.PickUpTime
orderby c.Дата
let pl = a.Пребукинг - (e.Child + e.Pax)
select new { kodg = a.КодГ, excursion = b.Название, guide = d.Name, data = c.Дата, pricead = b.Price,
pricech = b.PriceChd, pax = t.Колчел, child = t.Дети, paxleft = pl, pickup = pu.FirstOrDefault()};
return Ok(result);
}

Call Method from Linq query

I am using Linq query and call method Like..
oPwd = objDecryptor.DecryptIt((c.Password.ToString())
it will return null value.
Means this will not working.
how I Resolve this.
Thanks..
var q =
from s in db.User
join c in db.EmailAccount on s.UserId equals c.UserId
join d in db.POPSettings
on c.PopSettingId equals d.POPSettingsId
where s.UserId == UserId && c.EmailId == EmailId
select new
{
oUserId = s.UserId,
oUserName = s.Name,
oEmailId = c.EmailId,
oEmailAccId = c.EmailAccId,
oPwd = objDecryptor.DecryptIt(c.Password.ToString()),
oServerName = d.ServerName,
oServerAdd = d.ServerAddress,
oPOPSettingId = d.POPSettingsId,
};
If that is LINQ-to-SQL or Entity Framework. You'll need to break it into steps (as it can't execute that at the DB). For example:
var q = from s in db.User
join c in db.EmailAccount on s.UserId equals c.UserId
join d in db.POPSettings on c.PopSettingId equals d.POPSettingsId
where s.UserId == UserId && c.EmailId == EmailId
select new
{
oUserId = s.UserId,
oUserName = s.Name,
oEmailId = c.EmailId,
oEmailAccId = c.EmailAccId,
oPwd = c.Password,
oServerName = d.ServerName,
oServerAdd = d.ServerAddress,
oPOPSettingId = d.POPSettingsId,
};
then use AsEnumerable() to break "composition" against the back-end store:
var query2 = from row in q.AsEnumerable()
select new
{
row.oUserId,
row.oUserName,
row.oEmailId,
row.oEmailAccId,
oPwd = objDecryptor.DecryptIt(row.oPwd),
row.oServerName,
row.oServerAdd,
row.oPOPSettingId
};
var q = from s in db.User
join c in db.EmailAccount on s.UserId equals c.UserId
join d in db.POPSettings on c.PopSettingId equals d.POPSettingsId
where s.UserId == UserId && c.EmailId == EmailId
select new
{
oUserId = s.UserId,
oUserName = s.Name,
oEmailId = c.EmailId,
oEmailAccId = c.EmailAccId,
oPwd = c.Password,
oServerName = d.ServerName,
oServerAdd = d.ServerAddress,
oPOPSettingId = d.POPSettingsId,
};
foreach (var item in q)
{
item.oPwd = objDecryptor.DecryptIt(row.oPwd),
}
we can use a foreach loop also to update a single property. do not need to select all property in next query.
This has nothing about Linq query. you need to debug method objDecryptor.DecryptIt

Categories