Linq查询具有默认值 . 如果在DB Table中找不到此值,则应该从object获取默认值,稍后将在此表中添加新行 .
它应该是这样的,但这不起作用:
var name_country = (from m in ctx.person
where (m.name == oPerson.name || m.country == oPerson.country)
select new
{
m.name, m.country
}
).DefaultIfEmpty
(
oPerson.name,
oPerson.country
).FirstOrDefault();
如何在DefaultIfEmpty中设置此默认值???
新编辑:这是我想要作为一个查询:
string name = (from m in ctx.person
where (m.name == oPerson.name || m.country == oPerson.country)
select
m.name
).DefaultIfEmpty
(
oPerson.name,
).FirstOrDefault();
string country = (from m in ctx.person
where (m.name == oPerson.name || m.country == oPerson.country)
select
m.country
).DefaultIfEmpty
(
oPerson.country
).FirstOrDefault();