I’m using linq query to create my collection based on it’s id which is a guid.I’ve an item which can be associated to 1 or more products.What I need is to show all the productnames associated to that item and other datas like name,summary,date aswell.My issue here is when i try to use the variable i which is a guid in my array it throws error that Guid cannot be converted to int.I’m very sure that I’ve to convert my Guid array to int array but not sure how to implement it. below is my code.
foreach( Guid i in itemid)
{
var vals = from r in datacontext.ItemTable_s where r.itemID == i select r;
ItemTable_s[] tempdata = vals.ToArray<.ItemTable_s>();
Facet[] ftemp= new Facet[tempdata.Length];
ItemImage image = null;
string s1="";
for (int iv = 0; iv < tempdata.Length; iv++)
{
s1 += tempdata[i].productname + "\n";
}
ftemp[3] = new facet("Productname",facettype.text,s1);
collection.AddItem( tempdata[i].ItemName, null, null,
new ItemImage(new Uri(-tempdata[i].location))
);
}
In my above code tempdata[i] is where i get error msg saying guid cannot be converted to int implicitly.How do i fix this is there any other better approach?
(A GUID is 128 bits, so it cannot safely be converted into a 32-bit integer.)
A better option might be to use a
Dictionary<Guid, ItemTable_s>. Then you can still use GUIDs to index it.Then the line that’s currently raising an exception (
s1 += tempdata[i].productname + "\n";) should work as-is.This will also make your
itemidarray unnecessary. Alternatively you could keep the two arrays you’re using. Then you would have to change that line to:It looks like that is what you were intending to do. But that will be much slower than using a dictionary. It means you’ll be doing a sequential search of the
itemidarray every time you need to figure out where an entry is intempdata.