score:0
Accepted answer
dictionary<string, list<string>> dictionary_1 = new dictionary<string, list<string>> { };
dictionary<string, list<string>> dictionary_2 = new dictionary<string, list<string>> { };
// fill those dictionaries...
// check for non existing things in dictionary 2 but existing in 1
foreach (keyvaluepair<string, list<string>> _element in dictionary_1)
{
list<string> _valuesfrom2;
// check if table exist
if (dictionary_2.trygetvalue(_element.key, out _valuesfrom2))
{
//check if column exist
foreach (string _value in _element.value)
{
if (!_valuesfrom2.contains(_value))
{
console.writeline($"dictionary 2, table {_element.key} does not contain {_value}");
}
}
}
else
{
console.writeline($"dictionnary 2 does not contain : {_element.key}");
}
}
score:0
public static class joinextensions
{
public static ienumerable<tresult> fulloutergroupjoin<tleft, tright, tkey, tresult>(
this ienumerable<tleft> leftseq,
ienumerable<tright> rightseq,
func<tleft, tkey> keyselectorleft,
func<tright, tkey> keyselectorright,
func<ienumerable<tleft>, ienumerable<tright>, tkey, tresult> projectionselector,
iequalitycomparer<tkey> comparer = null)
{
comparer = comparer ?? equalitycomparer<tkey>.default;
var leftlookup = leftseq.tolookup(keyselectorleft, comparer);
var rightlookup = rightseq.tolookup(keyselectorright, comparer);
var keys = new hashset<tkey>(leftlookup.select(g => g.key), comparer);
keys.unionwith(rightlookup.select(g => g.key));
var join = keys
.select(key => projectionselector(leftlookup[key], rightlookup[key], key));
return join;
}
public static ienumerable<tresult> fullouterjoin<tleft, tright, tkey, tresult>(
this ienumerable<tleft> leftseq,
ienumerable<tright> rightseq,
func<tleft, tkey> keyselectorleft,
func<tright, tkey> keyselectorright,
func<tleft, tright, tkey, tresult> projectionselector,
tleft defaultleft = default(tleft),
tright defaultright = default(tright),
iequalitycomparer<tkey> comparer = null)
{
comparer = comparer ?? equalitycomparer<tkey>.default;
var leftlookup = leftseq.tolookup(keyselectorleft, comparer);
var rightlookup = rightseq.tolookup(keyselectorright, comparer);
var keys = new hashset<tkey>(leftlookup.select(g => g.key), comparer);
keys.unionwith(rightlookup.select(g => g.key));
var join = keys
.selectmany(
key => leftlookup[key].defaultifempty(defaultleft),
(key, leftitem) => new { key, leftitem })
.selectmany(
leftitemandkey =>
rightlookup[leftitemandkey.key]
.defaultifempty(defaultright),
(leftitemandkey, rightitem) =>
projectionselector(
leftitemandkey.leftitem,
rightitem,
leftitemandkey.key));
return join;
}
public static ienumerable<tresult> fullouterjoin<tleft, tright, tkey, tresult>(
this ienumerable<tleft> leftseq,
ienumerable<tright> rightseq,
func<tleft, tkey> keyselectorleft,
func<tright, tkey> keyselectorright,
func<tleft, tright, tresult> projectionselector,
tleft defaultleft = default(tleft),
tright defaultright = default(tright),
iequalitycomparer<tkey> comparer = null)
{
return leftseq
.fullouterjoin(
rightseq,
keyselectorleft,
keyselectorright,
(leftitem, rightitem, _) => projectionselector(leftitem, rightitem),
defaultleft,
defaultright,
comparer);
}
}
Source: stackoverflow.com
Related Query
- c#- select keys and values that does not exist in another dictionary
- The fastest way to find dictionary keys that are not exist in another list
- How to remove value that does not exist in another list?
- Select all from one List, replace values that exist on another List
- Compare two DataTables with several keys and select the rows that are not present in second table
- Get keys (objects) from a dictionary that contains list and filtered by values
- Linq - get objects with a list property that does not contain values in another list
- Get a random item from a collection that does not already exist in another collection - LINQ?
- LINQ: Getting Keys for a given list of Values from Dictionary and vice versa
- select rows that do not have any foreign keys linked
- Search dictionary values and return List of keys meeting conditions
- How to select values in list that are NOT IN a Table using EF Core?
- How do I combine the keys and values of a Dictionary into one List using LINQ?
- Errors 11 and 2002: "The EntityContainer ... does not exist in MetadataWorkspace"
- Which LINQ query to select rows from 1 table that are not in another table
- Select String that is not a property of another object
- LINQ query for finding one item in list AND verifying list does not contain another item
- Compare keys of dictionary with values of another dictionary
- Calculating the sum of the values in a dictionary that exist in a generic list
- List of objects to Dictionary with distinct keys and selected values
- Enumerable.Repeat with Union and Take does not return 'Take' values
- Simple LINQ select (using Entity Framework) does not return values
- Combining dictionary with possibly repeated keys into another dictionary containing the largest values
- Querying XML with LINQ and using null in place of a particular xml attribute if it does not exist
- How do I get a list of integers that exist in one collection, but not in another of a different type using LINQ?
- How to count the occurence of each number in list A that is exist in list B and return zero if not existed?
- Select records that have duration of StartDate and EndDate that not covered by Duration of given StartDate and EndDate
- VB.Net Linq with datatables - select from one table what does not exist in the other
- C# Linq with datatables - select from one table what does not exist in the other
- LINQ retrieve values from a table that of which fields(of a certain column) are not equal of another table
More Query from same tag
- Occasional performance drops in linq queries to concurrent bag
- Using AddRange from a list causes multiple database trips
- Entity framework add where clause to all queries
- Int list returned by LINQ query
- Sort and Take N from dictionary value in C#
- how to display orderby descending in LinQ
- How can I load the following XML using LINQ-to-XML into a dictionary?
- Extract Items from IEnumerable<ObservableCollection<T>> C#
- Does PLINQ really not preserve order?
- Load 1D array from xml with linq
- Mapping range variable EF Core to List for automapper
- How do I find a collection of nodes in HtmlAgilityPack using linq to xml?
- Change foreach loop to lambda
- InvalidCastException in a LINQ query
- Sort table with million rows , LinQ connection
- Using Linq to create a collection of a custom class from a DbSet that contains a list of grouped entities
- How can I use a Predicate<T> in an EF Where() clause?
- how to convert a sql query into linq LEFT OUTER JOIN
- Creating objects in C# out of XML using LINQ
- Modify MethodCallExpression arguments (C# LINQ)
- c# and mongodb: Aggregates with filter
- LINQ to join a lists of list-items into one list
- Returning Concatenated String with LINQ for Dropdown
- c# linq to xml XElement group by ancestor attribute to create list of entities collection with key
- How to use Join in select statement using linq expression
- not able to select in Group by Entity Framework
- How to find (and remove) a nested object from a List
- Returning a named tuple from a LINQ query
- Retrieve comma-separated values from IQueryable and add to list
- LinQ query doesn't order