score:1
Accepted answer
private internalorgdto getinternalorgdto(departmentchilddto dcdto)
{
var internalorgid = dcdto.internalorgid
?? findinternalorgid(dcdto.parentdepartmentid)
?? throw new internalorgnotfoundexception();
internalorgdto iodto = _context.internalorganizations
.where(x => x.internalorgid == internalorgid.value)
.select(x => new internalorgdto
{
id = x.id,
abbreviation = x.abbreviation,
code = x.code,
description = x.description
}).single();
return iodto;
}
private int? findinternalorgid(int? departmentid)
{
if (!departmentid.hasvalue)
return (int?) null;
var details = _context.departments
.where(x => x.departmentid == departmentid.value)
.select(x => new
{
x.internalorgid,
x.parentdepartmentid
}).single();
if (details.internalorgid.hasvalue)
return details.internalorgid;
return findinternalorgid(details.parentdepartmentid);
}
Source: stackoverflow.com
Related Query
- Recursive linq expressions to get non NULL parent value?
- How to get 0 out of a null linq query value when a condition isn't met and then set it to a ViewBag
- Get first value from table with where either have the value match or null with LINQ
- Linq to XML Get parent element attribute value by querying it's children
- Get data from a table after joining based on null value of joined table using LINQ
- Get attribute value of parent node by Linq to XML
- How to get NULL from LINQ When no value found in the joining tables
- C# - Using Linq get data if null value exist in query
- Recursive linq query to get parent list or child list from the given id
- C# LINQ - Get pairs, when second value is null in all pairs that have the same first value
- How can I get LINQ to return the object which has the max value for a given property?
- LINQ syntax where string value is not null or empty
- How to get distinct with highest value using Linq
- Get the parameter value from a Linq Expression
- Get Value from key using linq
- Return null instead default value in LINQ
- How to assign empty string if the value is null in linq query?
- How to get attribute value using LINQ to XML?
- LINQ - Returning value of a property of an object that is not null
- Linq GroupBy with each null value as a group
- How to get a value out of a Span<T> with Linq expression trees?
- Null value cannot be assigned - LINQ query question
- Linq recursive parent child
- Linq How to Get Average When all values equals null or 0 ? MVC
- LINQ question ... need to get element with min value
- Linq GroupBy on multiple columns with potentials null value
- Get excel cell value with Row and Column Position through open xml sdk linq query
- ListItemCollection - get text from value with LINQ
- Using LINQ to get DataGridView row index where first column has specific value
- Dynamic LINQ query to get Field value from Database
More Query from same tag
- Is it possible to combine 2 LINQ queries, each filtering data, before fetching the results of the queries?
- Using Linq to objects, ToDictionary method not satisfying type requirement
- linq left join with where clause show all from left table regardless
- Execute OrderBy with parameter
- How to implements Model in View when Linq Query is Distinct type in Action?
- Check for new items in an existing list LINQ/LAMBDA/C#
- Hot to get max value with where clause with EF5?
- Deleting selected relations in many-to-many relationship in EF?
- Why won't this LINQ join statement work?
- How to convert dynamic value to type value in expression
- Linq Query Using DataTable with Paging
- Sequence contains no elements error with linq
- Getting text from between two html nodes using HtmlAgilityPack
- Checking decimal for NULL in LINQ query
- Order By on the Basis of Dictint Group count
- LINQ - if condition
- How can i display/filter values of elements, using a different value of an element when a button is clicked
- Dynamic Linq SearchFor from entities by Passing Tablename,ColumnName and value as parameter
- Merging objects in List<Object> on two properties
- C# Dedupe a List with a List and Combine the List
- How to write "group by" + "sum" in just one clause?
- DataRows coming out null despite assigning values to them
- How to put a column from a database table into a dynamic list?
- LINQ in PowerShell with dynamically specified data types
- LIKE with Linq to Entities
- Need help to write SQL query as a linq expression
- deserialize xml into an array of objects, where each object contains nested classes
- MVC Linq using GroupBy Min Max and returning view
- C# LINQ DatabaseEntitie Query to first Value in Last Element results in Error
- how do i build dynamic linq queries at runtime using strings?