How to write this C# join with composite key clause in F#? :
join k in DataContext.Catalogs on
new { id = o.IDENT, v = o.VZ } equals
new { id = k.IDENT, v = k.VZ }
This is similiar question to this: groupby multiple columns in a F# 3.0 query which is still not answered. But I can't believe it is not easy possible to write it in FSharp.
Thanks
There are two methods available in Linq to perform Join Operations.
In LINQ, an inner join is used to serve a result which contains only those elements from the first data source that appears only one time in the second data source. And if an element of the first data source does not have matching elements, then it will not appear in the result data set.
The Join operator joins two sequences (collections) based on a key and returns a resulted sequence. GroupJoin. The GroupJoin operator joins two sequences based on keys and returns groups of sequences. It is like Left Outer Join of SQL.
A join clause takes two source sequences as input. The elements in each sequence must either be or contain a property that can be compared to a corresponding property in the other sequence. The join clause compares the specified keys for equality by using the special equals keyword.
Use tuples containing the key fields you want:
query {
for o in DataContext.OTable do
join k in DataContext.Catalogs on
((o.IDENT, o.VZ) = (k.IDENT, k.VZ))
select (o.IDENT, k.VZ)
}
Note that you can't create an anonymous type with named fields in F#, like you can in C#. Tuples are probably the closest and most idiomatic translation. See Tomas's answer here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With