vb.net - linq to sql to get single value -


i'm looking concise 1 line method single value datatable using lambda using vb.net

this code works

opt_udly = (from x in data.options                     x.contract = ctc                     select x.udly).single() 

but i'd value in 1 line (which doesn't work)

opt_udly = data.where(function(t) t.contract.equals(ctc)).distinct() 

any suggestions please?

try this:

opt_udly = data.options.where(function(t) t.contract = ctc).select(function(x) x.udly).single() 
  1. since use data.options in multiple linq lines, should consistently used single line too.
  2. also, since need udly element, use further select linq expression in single line style, did in multiple lines.
  3. and lastly, use single return matching value if there 1 match, did.

Comments