Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

i am having this error on the
basket.BasketId =  Guid.NewGuid();
and i get the the following intellisense saying "Cannot implicitly convert type system.Guid to int"
the basket.BasketId is having the type as int in my model so i want to know how i can fix that in the model for it to work. Thanks

What I have tried:

i have tried to use tryparse and all that but it not working i also want to know if i need to convert it to string from the model.
Posted
Updated 31-Oct-17 22:09pm
Comments
F-ES Sitecore 1-Nov-17 6:44am    
Go to the model and change the type of BasketId from int to Guid. I don't understand what the problem is?

1 solution

You can not convert a GUID to an integer type of .NET...
A GUID is a 128 bit number and the larges (built-in) integer type is 64 bit...
 
Share this answer
 
Comments
taiwokaffo 1-Nov-17 4:29am    
i really need to know i can have a Guid.NewGuid method have it values stored in a variable.
Kornfeld Eliyahu Peter 1-Nov-17 4:37am    
Where do you want to store it?
taiwokaffo 1-Nov-17 4:42am    
this is what the code looks like

private Basket createNewBasket(HttpContextBase httpContext)
{

HttpCookie cookie = new HttpCookie(BasketSessionName);
Basket basket = new Basket();
basket.date = DateTime.Now;
basket.BasketId = Guid.NewGuid();

baskets.Insert(basket);
baskets.Commit();

cookie.Value = basket.BasketId.ToString();
cookie.Expires = DateTime.Now.AddDays(1);
httpContext.Response.Cookies.Add(cookie);

return basket;

}
and the basket model has the BasketId as an int with {get;set;}
Kornfeld Eliyahu Peter 1-Nov-17 4:49am    
As explained GUID can not convert to int (not enough room), so you have to change BasketID's type... Try string... GUID has a nice ToString method...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900