SBendBuckeye
Programmer
Can anyone help me translate this C# Linq code into VB.Net? It came from Comparing DataSets using LINQ: Thanks!
var orig = dsOriginal.Tables[0].AsEnumerable();
var updated = dsChanged.Tables[0].AsEnumerable();
//First, getting new records if any
var newRec = from u in dsChanged
where !(from o in orig
select o.Field<decimal>("PRIMARY_KEY_FIELD"))
.Contains(u.Field<decimal>(" PRIMARY_KEY_FIELD"))
select new
{
prim_key = u.Field<decimal>("PRIMARY_KEY_FIELD"),
field1 = u.Field<decimal>("FIELD1"),
field2=u.Field<decimal>("FIELD2"),
field3 = u.Field<decimal>("FIELD3"),
field4 = u.Field<decimal>("FIELD4"),
rec_type="A"//Added
};
//Secondly, getting updated records
var updRec = from u in updated
join o in orig
on u.Field<decimal>("PRIMARY_KEY_FIELD")
equals o.Field<decimal>("PRIMARY_KEY_FIELD")
where (u.Field<decimal>("FIELD1") !=
o.Field<decimal>("FIELD1")) ||
(u.Field<decimal>("FIELD2") !=
o.Field<decimal>("FIELD2"))
select new
{
prim_key = u.Field<decimal>("PRIMARY_KEY_FIELD"),
field1 = u.Field<decimal>("FIELD1"),
field2=u.Field<decimal>("FIELD2"),
field3 = u.Field<decimal>("FIELD3"),
field4 = u.Field<decimal>("FIELD4"),
rec_type = "M"//Mofified
};
var Union = newRec.Union(updRec);
var orig = dsOriginal.Tables[0].AsEnumerable();
var updated = dsChanged.Tables[0].AsEnumerable();
//First, getting new records if any
var newRec = from u in dsChanged
where !(from o in orig
select o.Field<decimal>("PRIMARY_KEY_FIELD"))
.Contains(u.Field<decimal>(" PRIMARY_KEY_FIELD"))
select new
{
prim_key = u.Field<decimal>("PRIMARY_KEY_FIELD"),
field1 = u.Field<decimal>("FIELD1"),
field2=u.Field<decimal>("FIELD2"),
field3 = u.Field<decimal>("FIELD3"),
field4 = u.Field<decimal>("FIELD4"),
rec_type="A"//Added
};
//Secondly, getting updated records
var updRec = from u in updated
join o in orig
on u.Field<decimal>("PRIMARY_KEY_FIELD")
equals o.Field<decimal>("PRIMARY_KEY_FIELD")
where (u.Field<decimal>("FIELD1") !=
o.Field<decimal>("FIELD1")) ||
(u.Field<decimal>("FIELD2") !=
o.Field<decimal>("FIELD2"))
select new
{
prim_key = u.Field<decimal>("PRIMARY_KEY_FIELD"),
field1 = u.Field<decimal>("FIELD1"),
field2=u.Field<decimal>("FIELD2"),
field3 = u.Field<decimal>("FIELD3"),
field4 = u.Field<decimal>("FIELD4"),
rec_type = "M"//Mofified
};
var Union = newRec.Union(updRec);