How can I do this conversion? Is it possible with some simple LINQ query?
If V is some other type not involved in the query, you can use the let keyword to create an instance and then group on it...
from x in Y
let v = new V(x.Whatever)
group v by v.Whatever into vGroup
select vGroup
Assuming that V inherits from U and you want to cast each U to a V :
IEnumerable<IGrouping<string, U>> groupingsOfU =
from u in listOfU
group u by u.Foo;
IEnumerable<IGrouping<string, V>> groupingsOfV =
from g in groupingsOfU
from u in g
group (V)u by g.Key;
Related
In Graphql, I can create a union such as the following:
union SearchResult = Book | Movie
Is there a way I can do this for plain strings? Something like this:
union AccountRole = "admin" | "consumer"
I am afraid you cannot do that because it is what defined by the specification.
From the union syntax mentioned at specification here , the part that you want to change should follow the Names syntax , which the first character is only allow to be upper case letter, lower case latter or _
(i.e. the characters set as follows)
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m
n o p q r s t u v w x y z _
Help me with this please.
I have this input column in a datatable
First Case: Second Case: Third Case:
Operation Operation Operation
C C V
C C V
V C V
V C V
C C V
C C V
V C V
C C V
V C V
And I want to know if the dt has C and V or just C or just V.
First you need 2 boolean variables to store the information if C and V exist or not. After that you need to loop through your dt using for each row activity. Inside foreach activity you can use an if activity with assign activty to compare row value with "C" or "V" and set the values of variables accordingly. Finally you can use the values of these variables to decide if your datatable has C and V or just C or just V.
I am very new to Prolog, and would appreciate any help.
I want to implement the following in Prolog:
combine (A,B,C)
D = A/1,
E = B/3,
and C = A + B , in which given expression of A,B, C will return as A/1 + E/3, rather than calculating its value.
Many thanks!
I want to do something like
let switchgraph cases =
let g = Graph.makeGraph() in
let g = (Graph.addNode g 1) in
for i = 2 to cases do
let g = (Graph.addNode g i) in
done
g
But apparently, this is not possible. How else can i achieve this.
There are two things you need to fix:
you need to use references (see ref, := and !) for this, since let bindings are immutable
to sequence two expressions, you need to use ;
Something like this should work:
let switchgraph cases =
let g = ref (Graph.makeGraph()) in
g := Graph.addNode (!g) 1;
for i = 2 to cases do
g := Graph.addNode (!g) i
done;
!g
Note that g is the reference, and !g the value.
Hi may i know how to do a select "case" condition in using linq?
The commented out code are my question. how do i put the condition there?
my code:
var r = from u in Users
join p in Payments on u.Id equals p.UserId
join soi in SaleOrderItems on p.ReferenceId equals soi.Id
//if soi.InventoryTypeId == 1
//then join i in Inventories on soi.InventoryOrCourseId equals i.Id
//elseif soi.InventorytypeId ==2
//then join c in Courses on soi.InventoryOrCourseId equals c.Id
where u.Id == 5
select new{ u, p, soi, either i or c};
You have to use some outer join trick to accomplish this, one straightforward method is via DefaultIfEmpty(). Essentially you create an inner join then expand it with missing rows:
var r = from u in Users
join p in Payments on u.Id equals p.UserId
join soi in SaleOrderItems on p.ReferenceId equals soi.Id
join i in Inventories on new {a = soi.InventoryTypeId, b = soi.InventoryOrCourseId } equals new {a = 1, b = i.Id} into g1
from oi in g1.DefaultIfEmpty()
join c in Courses on new {a = soi.InventoryTypeId, b = soi.InventoryOrCourseId } equals new {a = 2, b = c.Id} into g2
from oc in g2.DefaultIfEmpty()
where u.Id == 5
select new{ u, p, soi, ic = oi ?? oc};
Be careful about this last statement ic = oi ?? oc, since the types differ the anonymous type will use System.Object declaration so it can accommodate both types, if you want to use strong typed support maybe a better option would be to return both oc and ic and then test. You should best decide that based on how you use this query late ron.