Below is the query,
List<int> groupIdList = {1, 2};
var clientGroupData = from cge in base.context.Set<ClientGroupEngagement>()
join cg in base.context.Set<ClientGroup>() on cge.ClientGroupID equals cg.ClientGroupID
join cgu in base.context.Set<ClientGroupUser>() on cg.ClientGroupID equals cgu.ClientGroupID
join eng in base.context.Set<Engagement>() on cge.EngagementID equals eng.EngagementID
join cdc in base.context.Set<CountryDataCenter>()
on new { eng.CountryID, eng.EngagementVersion } equals new { cdc.CountryID, cdc.EngagementVersion }
join dc in base.context.Set<DataCenter>()
on cdc.DataCenterID equals dc.DataCenterID
join dcuri in base.context.Set<DataCenterURI>()
on new { dc.DataCenterID, cdc.EngagementVersion } equals new { dcuri.DataCenterID, dcuri.EngagementVersion }
join uritype in base.context.Set<URIType>()
on dcuri.URITypeID equals uritype.URITypeID
where groupIdList.Contains(cgu.ClientGroupID)
&& cg.IsActive
&& cdc.IsActive
&& dc.IsActive
&& dcuri.IsActive
&& uritype.IsActive
&& (dcuri.URITypeID == (int)URITypeEnum.WebUri || dcuri.URITypeID == (int)URITypeEnum.AppUri)
select new ClientGroupUserEngagementModel
{
EngagementId = cge.EngagementID,
EngagementDescription = eng.EngagementDescription,
EngagementStatusId = eng.EngagementStatusID,
ClientGroupId = cg.ClientGroupID,
ClientGroupGuid = cg.ClientGroupGUID,
ClientGroupName = cg.ClientGroupName,
UserId = cgu.ClientUserID,
FirstName = cgu.FirstName,
LastName = cgu.LastName,
IsGroupUserActive = cgu.IsActive,
LocatorDataModel = new LocatorDataModel
{
DatacenterId = cdc.DataCenterID,
DatacenterName = dc.DataCenterName,
EngagementVersion = cdc.EngagementVersion,
Uri = dcuri.URI,
UriTypeId = dcuri.URITypeID
},
};
var result = await clientGroupData.ToListAsync();
I am expecting list of LocatorDataModel in the result set. EngagementId is key which will be unique.
Currently it is pulling *2 records due to condition
(dcuri.URITypeID == (int)URITypeEnum.WebUri || dcuri.URITypeID == (int)URITypeEnum.AppUri)
How can get result like
Engagementid 1 : dataurl1 dataurl2
Engagementid 2: dataurl3 dataurl4, dataurl5
etc.
Any help is appreciated.
I think below sample code can help you:
var list = new[]
{
new { Engagementid = 1, Dataurl = "dataurl1"},
new { Engagementid = 1, Dataurl = "dataurl2"},
new { Engagementid = 2, Dataurl = "dataurl3"},
new { Engagementid = 2, Dataurl = "dataurl4"},
new { Engagementid = 2, Dataurl = "dataurl5"}
};
var result =
list.GroupBy(g => g.Engagementid)
.Select(c => new {Engagementid = c.Key, Dataurls = string.Join(",", c.Select(x=> x.Dataurl).ToList())})
.ToList();
That result will be:
[0]: { Engagementid = 1, Dataurls = "dataurl1,dataurl2" }
[1]: { Engagementid = 2, Dataurls = "dataurl3,dataurl4,dataurl5" }
Related
I know you cannot cannot directly use the tSQL PIVOT function in Linq, but I cannot get the correct Linq syntax for what I feel is a simple transform (which I can do in straight tSQL)
I need to take this data set:
and pivot it into this:
Can someone please help me with the correct Linq syntax?
Here's how I can accomplish this in tSQL (both using PIVOT() and not)
Select piv.* from (
select custom_data_key, custom_data_value from dbo.kb_article_custom_data cd
inner join dbo.kb_article kb on cd.article_id = kb.article_id
where (custom_data_key='article_problem' or custom_data_key = 'article_cause' or custom_data_key='article_solution') and article_number='AKB26'
) d
pivot
(max(custom_data_value) for custom_data_key in([article_problem],[article_cause], [article_solution])) piv;
--WITHOUT USING PIVOT()
select
max(case when t.[custom_data_key]='article_problem' then t.[custom_data_value] end) as Article_problem,
max(case when t.[custom_data_key]='article_cause' then t.[custom_data_value] end) as Article_cause,
max(case when t.[custom_data_key]='article_solution' then t.[custom_data_value] end) as Article_solution
from(select custom_data_key, custom_data_value from dbo.kb_article_custom_data cd
inner join dbo.kb_article kb on cd.article_id = kb.article_id
where (custom_data_key='article_problem' or custom_data_key = 'article_cause' or custom_data_key='article_solution') and article_number='AKB26')t
This LINQ statement will get me the results in the first image above:
var query =
from a in custdata
join b in kbase on a.article_id equals b.article_id
where (a.custom_data_key == "article_problem" || a.custom_data_key == "article_cause" || a.custom_data_key == "article_solution") && b.article_number == id
select new { Key = a.custom_data_key, Value = a.custom_data_value };
Here's what is failing. I take the results of the Linq query above-
var q2 = from row in query
group row by "Value" into g
select new TO_Kbase
{
Problem= g.Where(c => c.Key =="article_problem" ).Select(c => c.Value).ToString(),
Cause = g.Where(c => c.Key =="article_cause").Select(c => c.Value).ToString(),
Solution = g.Where(c => c.Key =="article_solution").Select(c => c.Value).ToString()
};
foreach(var x in q2)
{
TO_Kbase kb = new TO_Kbase();
kb.Problem =x.Problem;
kb.Cause = x.Cause;
kb.Solution = x.Solution;
ta.Add(kb);
}
The output is this:
Problem: System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1+d__0`1[System.Data.SqlClient.SqlDataReader,System.String]
Cause: System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1+d__0`1[System.Data.SqlClient.SqlDataReader,System.String]
Solution: System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1+d__0`1[System.Data.SqlClient.SqlDataReader,System.String]
If I understood your data structure correctly, you could do something very similar to your "WITHOUT USING PIVOT()" T-SQL query:
// Test data.
var kb_article_custom_data = new CustomData[] {
new CustomData() { article_id = 1, custom_data_key = "article_problem", custom_data_value = "when you try ... 1"},
new CustomData() { article_id = 1, custom_data_key = "article_cause", custom_data_value = "the issues may occur ... 1"},
new CustomData() { article_id = 1, custom_data_key = "article_solution", custom_data_value = "1. Click start, then ... 1"},
new CustomData() { article_id = 2, custom_data_key = "article_problem", custom_data_value = "when you try ... 2"},
new CustomData() { article_id = 2, custom_data_key = "article_cause", custom_data_value = "the issues may occur ... 2"},
new CustomData() { article_id = 2, custom_data_key = "article_solution", custom_data_value = "1. Click start, then ... 2"},
new CustomData() { article_id = 3, custom_data_key = "article_problem", custom_data_value = "when you try ... 3"},
//new CustomData() { article_id = 3, custom_data_key = "article_cause", custom_data_value = "the issues may occur ... 3"},
new CustomData() { article_id = 3, custom_data_key = "article_solution", custom_data_value = "1. Click start, then ... 3"},
};
var kb_article = new Article[] {
new Article() { article_id = 1, article_title = "Title ... 1"},
new Article() { article_id = 2, article_title = "Title ... 2"},
new Article() { article_id = 3, article_title = "Title ... 3"},
};
// Query resembling your "without pivot" query.
var result =
from article in kb_article
join custom in kb_article_custom_data on article.article_id equals custom.article_id into ac
select new {
id = article.article_id,
title = article.article_title,
problem = ac.Where(x => x.custom_data_key == "article_problem").Select(x => x.custom_data_value).FirstOrDefault(x => x != null),
cause = ac.Where(x => x.custom_data_key == "article_cause").Select(x => x.custom_data_value).FirstOrDefault(x => x != null),
solution = ac.Where(x => x.custom_data_key == "article_solution").Select(x => x.custom_data_value).FirstOrDefault(x => x != null)
};
foreach (var r in result)
Console.WriteLine(r);
Which produces the following output:
{ id = 1, title = Title ... 1, problem = when you try ... 1, cause = the issues may occur ... 1, solution = 1. Click start, then ... 1 }
{ id = 2, title = Title ... 2, problem = when you try ... 2, cause = the issues may occur ... 2, solution = 1. Click start, then ... 2 }
{ id = 3, title = Title ... 3, problem = when you try ... 3, cause = , solution = 1. Click start, then ... 3 }
If you want to filter by a specific article_id, you need to add a where clause:
var id = 1;
var result =
from article in kb_article
where article.article_id == id
join custom in kb_article_custom_data on article.article_id equals custom.article_id into ac
select new
{
id = article.article_id,
title = article.article_title,
problem = ac.Where(x => x.custom_data_key == "article_problem").Select(x => x.custom_data_value).FirstOrDefault(x => x != null),
cause = ac.Where(x => x.custom_data_key == "article_cause").Select(x => x.custom_data_value).FirstOrDefault(x => x != null),
solution = ac.Where(x => x.custom_data_key == "article_solution").Select(x => x.custom_data_value).FirstOrDefault(x => x != null)
};
Producing the following output:
{ id = 1, title = Title ... 1, problem = when you try ... 1, cause = the issues may occur ... 1, solution = 1. Click start, then ... 1 }
Solution:
var query =
from a in custdata
join b in kbase on a.article_id equals b.article_id into ac
where (a.custom_data_key == "article_problem" || a.custom_data_key == "article_cause" || a.custom_data_key == "article_solution") && a.article_id == id
group a by new { a.article_id} into abc
select new
{
ID = abc.Key.article_id,
Cause = abc.Where(a =>a.custom_data_key == "article_cause").Select(a => a.custom_data_value).FirstOrDefault(x => x != null),
Problem = abc.Where(a => a.custom_data_key == "article_problem").Select(a => a.custom_data_value).FirstOrDefault(x => x != null),
Solution = abc.Where(a => a.custom_data_key == "article_solution").Select(a => a.custom_data_value).FirstOrDefault(x => x != null)
};
I need help please!
When I perform the following LINQ query, it works perfectly (shows results)
using (var db = new MyEntities())
{
var result = (from dc in db.ClassDiary
where dc.DesTurm == dataForm.DesTurma
&& dc.Module == dataForm.Module
&& dc.CodDisc == dataForm.CdDisc
orderby dc.NrDiary
select new ClassDiaryMod
{
Id = dc.ID,
NrDiary = dc.NrDiary,
NrStudant = dc.NrStudant,
DesTurma = dc.DesTurma,
CdDisc = dc.CodDisc,
CdTeac = dc.CodTeac,
TotalFoult = (from f in db.Foult
where
f.NrStudant == dc.NrStudant &&
f.Disc == dc.CodDisc
select new FoultMod
{
Foults = f.Foult
}).Sum(x => x.Foults)
}).ToList();
return result;
When I try to apply the left join with multiple key does not display results
using (var db = new FamespEntities())
{
var result = (from dc in db.ClassDiary
join fn in db.Foult
on new { dc.NrStudant, dc.CodDisc, dc.DesTurm }
equals new { fn.NrStudant, CodDisc = fn.Disc, DesTurm = fn.Desturm } into fn_join
from fn in fn_join.DefaultIfEmpty()
where dc.DesTurm == dataForm.DesTurm
&& dc.Module == dataForm.Module
&& dc.CodDisc == dataForm.CdDisc
orderby dc.NroDiary
select new ClassDiaryMod
{
Id = dc.Id,
NrDiary = dc.NroDiary,
NrStudant = dc.NrStudant,
DesTurm = dc.DesTurm,
CdDisc = dc.CodDisc,
CdTeac = dc.CodTeac,
FoultOfDay = fn.Foult,
TotalFoults = (from f in db.Foult
where
f.NrStudent == dc.NrStudant &&
f.Disc == dc.CodDisc
select new FoultMod
{
Foults = f.Foult
}).Sum(x => x.Foults)
}).ToList();
Like to understand why the first code works and the second does not.
Thank you so much
Your equals
on new { dc.NrStudant, dc.CodDisc, dc.DesTurm }
equals new { fn.NrStudant, CodDisc = fn.Disc, DesTurm = fn.Desturm }
Is not correct, it should be
on new { NrStudant = dc.NrStudant, CodDisc = dc.CodDisc, DesTurm = dc.DesTurm }
equals new { NrStudant = fn.NrStudant, CodDisc = fn.Disc, DesTurm = fn.Desturm }
so field comparison could work.
i have this linq query
var x = (from d in detalle
from n in nlj.DefaultIfEmpty()
join nd in nuevodetalle
on new { d.ope_idsku ,d.ope_tipo } equals new {nd.ope_idsku ,nd.ope_tipo }into nlj
from n in nlj.DefaultIfEmpty()
select new { d, n } ).ToList();
now if i do it
x[0].d==null this return false
x[0].n==null this return false
x[1].d==null this return false
x[1].n==null this fails, why?
my real select is not {d,n } it is
select new ope_detalle_autoventa()
{
CreatedOn = d.CreatedOn,
ModifiedOn = d.ModifiedOn,
ope_autoventaid = d.ope_autoventaid,
ope_Codope = d.ope_Codope,
ope_detalle_autoventaId = (tiene_nuevo_primarykey) ? Guid.NewGuid() : d.ope_detalle_autoventaId,
ope_entregado = (d.ope_entregado - (n != null ? n.ope_entregado : 0)),
ope_envase = d.ope_envase,
ope_estado = d.ope_estado,
ope_icono = d.ope_icono,
ope_idsku = d.ope_idsku,
ope_name = d.ope_name,
ope_pedido = d.ope_pedido,
ope_precioV = d.ope_precioV,
ope_prestamo = d.ope_prestamo,
ope_promocion = d.ope_promocion,
ope_skuid = d.ope_skuid,
ope_tipo = d.ope_tipo,
ope_autoventaidTarget = d.ope_autoventaidTarget,
ope_skuidTarget = d.ope_skuidTarget,
Ope_NumVenta = d.Ope_NumVenta,
ope_descuento = d.ope_descuento,
ope_cancelado = d.ope_cancelado,
ope_folio = d.ope_folio,
ope_cantcanc = 0,
ope_estimado = "0"
}
but this get fails same reason x[1].n==null fails, (that i believe),
i believe this fails at this line
ope_entregado = (d.ope_entregado - (n != null ? n.ope_entregado : 0)),
however
this query doesn't fail
var restaragregados = (from r in resultadoregresar
group new { r.ope_entregado } by new { r.ope_idsku } into agrupacion
select new { agrupacion.Key.ope_idsku, entregadototal=(agrupacion.Sum (x=> x.ope_entregado) ) }
);
List<ope_detalle_autoventa> nuevodetalle = (from d in detalle
join c in cargainventario
on d.ope_idsku equals c.ope_idsku into clj
from c in clj.DefaultIfEmpty()
join r in restaragregados on
d.ope_idsku equals r.ope_idsku into rlj
from r in rlj.DefaultIfEmpty ()
where (c!=null?c.ope_carga == cargausada:c==null )
&& (d.ope_entregado > ((c==null ?0:c.ope_disponibles ) - (r==null?0:r.entregadototal)))
&& d.ope_tipo ==tipos[i]
select new ope_detalle_autoventa()
{
ModifiedOn = DateTime.Now,
ope_autoventaid = ope_autoventaid,
ope_detalle_autoventaId = d.ope_detalle_autoventaId,
ope_entregado = (d.ope_entregado - ((c== null ? 0 : c.ope_disponibles) - (r == null ? 0 : r.entregadototal))),
ope_envase = d.ope_envase,
ope_estado = d.ope_estado,
ope_icono = d.ope_icono,
ope_idsku = d.ope_idsku,
ope_name = d.ope_name,
ope_pedido = 0,//0 por que no pidio de esta carga sino de la que ya se gastó
ope_precioV = d.ope_precioV,
ope_prestamo = d.ope_prestamo,
ope_promocion = d.ope_promocion,
ope_skuid = d.ope_skuid,
ope_tipo = d.ope_tipo,
ope_autoventaidTarget = d.ope_autoventaidTarget,
ope_skuidTarget = d.ope_skuidTarget,
Ope_NumVenta = d.Ope_NumVenta,
ope_descuento = d.ope_descuento,
ope_cancelado =d.ope_cancelado ,
CreatedOn =DateTime.Now ,
ope_Codope =d.ope_Codope ,
ope_folio =d.ope_folio,
ope_cantcanc =0,
ope_estimado="0"
}
).ToList();
i rename n by c and i change
on new { d.ope_idsku ,d.ope_tipo } equals new {nd.ope_idsku ,nd.ope_tipo }into nlj
by d.ope_idsku equals nd.ope_idsku into nlj
but i get the same error.
I solved with this
if (nuevodetalle.Count == 0)
nuevodetalle.Add(detalle [0]);
ope_detalle_autoventa clone = (ope_detalle_autoventa)detalle[0].Clone();
clone.ope_idsku = 0;
clone.ope_entregado = 0;
clone.ope_tipo = 0;
List<ope_detalle_autoventa> detallecargaactual = new List<ope_detalle_autoventa>();
var x = (
from d in detalle
join c in nuevodetalle
//on new { d.ope_idsku, d.ope_tipo } equals new { c.ope_idsku, c.ope_tipo } into clj
on d.ope_idsku equals c.ope_idsku into clj
from c in clj.DefaultIfEmpty (clone)
select new{ d, c}).ToList();`enter code here
you can see i changed clj.DefaultIfEmpty (clone)
Take a look at my code here:
public static ItemType GetItem(int id)
{
ItemType it = new ItemType();
using (var context = matrix2.matrix2core.DataAccess.Connection.GetContext())
{
var q = (from ci in context.Item
where ci.ID == id
let TemplateID = ci.TemplateID
let Groups = from x in context.CriteriaGroup
where x.TemplateID == TemplateID
select new
{
x
}
let CriteriaItems = from x in context.CriteriaItem
where Groups.Select(y => y.x.ID).Contains(x.CriteriaGroupID)
select new
{
x
}
select new
{
ci.ID,
ci.Name,
ci.CategoryID,
ci.Description,
ci.ItemValue,
TemplateID,
Groups,
CriteriaItems,
ItemValues = from x in context.ItemValue
where x.ItemID == id
select new
{
x,
CriteriaID = x.CriteriaItem.Criteria.ID
}
}).FirstOrDefault();
if (q != null)
{
it.ID = q.ID;
it.CategoryID = q.CategoryID;
it.Name = q.Name;
it.TemplateID = q.TemplateID;
it.Description = q.Description;
it.CriteriaGroups = new List<CriteriaGroupType>();
it.CriteriaItems = new List<CriteriaItemType>();
it.ItemValues = new List<ItemValueType>();
foreach (var x in q.ItemValues)
{
ItemValueType ivt = new ItemValueType();
ivt.CriteriaItemID = x.x.CriteriaItemID;
ivt.CriteriaID = x.CriteriaID;
ivt.Data = x.x.Data;
ivt.ID = x.x.ID;
ivt.ItemID = x.x.ItemID;
it.ItemValues.Add(ivt);
}
/////////error when I added the orderby clause
foreach (var x in q.Groups.OrderBy(x => x.x.SortOrder))
{
CriteriaGroupType cgt = new CriteriaGroupType();
cgt.ID = x.x.ID;
cgt.Name = !string.IsNullOrEmpty(x.x.Name) ? x.x.Name : "Group" + x.x.ID;
cgt.SortOrder = x.x.SortOrder;
cgt.TemplateID = x.x.TemplateID;
it.CriteriaGroups.Add(cgt);
}
/////////error when I added the orderby clause
foreach (var temp in q.CriteriaItems.OrderBy(x => x.x.SortOrder))
{
CriteriaItemType cit = new CriteriaItemType();
cit.ID = temp.x.ID;
cit.CriteriaGroupID = temp.x.CriteriaGroupID;
cit.GroupName = (temp.x.Name != null) ? temp.x.Name : "Group" + temp.x.ID;
cit.CriteriaID = temp.x.CriteriaID;
cit.CriteriaName = temp.x.Criteria.Name;
cit.Name = !string.IsNullOrEmpty(temp.x.Name) ? temp.x.Name : temp.x.Criteria.Name;
cit.Options = temp.x.Options;
it.CriteriaItems.Add(cit);
}
}
}
return it;
}
Instead of letting SQL handle the sorting (OrderBy) I wanted asp.net to do the sorting instead. I took the sorting out of the SQL linq query and put it on the foreach loop. When I did that I got the error. Is there a way to fix this?
You should be able to go from IQueryable to IEnumerable with a simple
var q2 = q.ToList();
What I meant of course was :
var groups = q.Groups.ToList();
I am facing a scenario where I have to filter a single object based on many objects.
For sake of example, I have a Grocery object which comprises of both Fruit and Vegetable properties. Then I have the individual Fruit and Vegetable objects.
My objective is this:
var groceryList = from grocery in Grocery.ToList()
from fruit in Fruit.ToList()
from veggie in Vegetable.ToList()
where (grocery.fruitId = fruit.fruitId)
where (grocery.vegId = veggie.vegId)
select (grocery);
The problem I am facing is when Fruit and Vegetable objects are empty.
By empty, I mean their list count is 0 and I want to apply the filter only if the filter list is populated.
I am also NOT able to use something like since objects are null:
var groceryList = from grocery in Grocery.ToList()
from fruit in Fruit.ToList()
from veggie in Vegetable.ToList()
where (grocery.fruitId = fruit.fruitId || fruit.fruitId == String.Empty)
where (grocery.vegId = veggie.vegId || veggie.vegId == String.Empty)
select (grocery);
So, I intend to check for Fruit and Vegetable list count...and filter them as separate expressions on successively filtered Grocery objects.
But is there a way to still get the list in case of null objects in a single query expression?
I think the LINQ GroupJoin operator will help you here. It's similar to the TSQL LEFT OUTER JOIN
IEnumerable<Grocery> query = Grocery
if (Fruit != null)
{
query = query.Where(grocery =>
Fruit.Any(fruit => fruit.FruitId == grocery.FruitId));
}
if (Vegetable != null)
{
query = query.Where(grocery =>
Vegetable.Any(veggie => veggie.VegetableId == grocery.VegetableId));
}
List<Grocery> results = query.ToList();
Try something like the following:
var joined = grocery.Join(fruit, g => g.fruitId,
f => f.fruitId,
(g, f) => new Grocery() { /*set grocery properties*/ }).
Join(veggie, g => g.vegId,
v => v.vegId,
(g, v) => new Grocery() { /*set grocery properties*/ });
Where I have said set grocery properties you can set the properties of the grocery object from the g, f, v variables of the selector. Of interest will obviouly be setting g.fruitId = f.fruitId and g.vegeId = v.vegeId.
var groceryList =
from grocery in Grocery.ToList()
join fruit in Fruit.ToList()
on grocery.fruidId equals fruit.fruitId
into groceryFruits
join veggie in Vegetable.ToList()
on grocery.vegId equals veggie.vegId
into groceryVeggies
where ... // filter as needed
select new
{
Grocery = grocery,
GroceryFruits = groceryFruits,
GroceryVeggies = groceryVeggies
};
You have to use leftouter join (like TSQL) for this. below the query for the trick
private void test()
{
var grocery = new List<groceryy>() { new groceryy { fruitId = 1, vegid = 1, name = "s" }, new groceryy { fruitId = 2, vegid = 2, name = "a" }, new groceryy { fruitId = 3, vegid = 3, name = "h" } };
var fruit = new List<fruitt>() { new fruitt { fruitId = 1, fname = "s" }, new fruitt { fruitId = 2, fname = "a" } };
var veggie = new List<veggiee>() { new veggiee { vegid = 1, vname = "s" }, new veggiee { vegid = 2, vname = "a" } };
//var fruit= new List<fruitt>();
//var veggie = new List<veggiee>();
var result = from g in grocery
join f in fruit on g.fruitId equals f.fruitId into tempFruit
join v in veggie on g.vegid equals v.vegid into tempVegg
from joinedFruit in tempFruit.DefaultIfEmpty()
from joinedVegg in tempVegg.DefaultIfEmpty()
select new { g.fruitId, g.vegid, fname = ((joinedFruit == null) ? string.Empty : joinedFruit.fname), vname = ((joinedVegg == null) ? string.Empty : joinedVegg.vname) };
foreach (var outt in result)
Console.WriteLine(outt.fruitId + " " + outt.vegid + " " + outt.fname + " " + outt.vname);
}
public class groceryy
{
public int fruitId;
public int vegid;
public string name;
}
public class fruitt
{
public int fruitId;
public string fname;
}
public class veggiee
{
public int vegid;
public string vname;
}
EDIT:
this is the sample result
1 1 s s
2 2 a a
3 3