GUID Cast Exception - crm

I'm using the following code in CRM 4.0 to get the GUID, but it is giving me a casting exception:
Guid id=new Guid(entity.Properties["incidentid"].ToString());
What is the correct way to do this?

Try to use following:
Guid id = ((Key)entity["incidentid"]).Value;

Related

Xamarin SQLIteConnection: method "Get" throw exception if key doesn't exist

When I try run this code:
var l=_sqliteconnection.Get<Preferences> (x=>x.Key=="Login");
I have got exception, because entity in table "Preferences" with key "Login" doesn't exist, but if entity exist, it's ok.
I can use try/catch blocks, but can I do it without try and catch?
Thank you.
From Get<TClass> class documentation on returns:
The object that matches the given predicate. Throws a not found exception if the object is not found
If you don't want the exception it's better to use Find<TClass> that get the object with the given primary key or null if the object is not found.

asp.net mvc: more info on UpdateModel exception

i sometimes get an error with the UpdateModel function.
However, i can't seem to locate the exact message which field(s) is/are causing the problem.
For example this one:
"The model of type 'Enquete' was not successfully updated."
it has an innerexception of NULL, and no further description. Is there a way to find out what is causing the problem?
Michel
EDIT:
i see this in my output window:
"A first chance exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll"
Steve Sanderson has a wonderful article on using the MVC source to help you debug your application.
I think this will help you get more info.
Kindness,
Dan
Just a wild guess: You are trying to bind null to a value type. Check in your model for int, float, DateTime, structs, ... data types that you try to bind to null.
I was getting this type of exception and from my experience i got what was causing it...
We have one primary key field or identity field in the entity...
If we try to display that field in the view using html control like text box and all then at that time updateModel throws exception
otherwise it wont throw exception
Use TryUpdateModel instead. It won't throw exception, but then you can inspect ModelState for errors.
I know it is late but to help others.

Trouble creating new Entity Data Model

I'm trying to add a new ADO.Net Entity Data Model to an MVC project I am working on.
When I complete the wizard, choosing my db and tables (just a single table for now) I get an error ""Exception has been thrown by the target of an invocation." and it throws me back the add new item dialog.
At this point, an empty Data Model has been created in my project. If I then choose "Update Model From Database" and complete the wizard again, I get a similar error.
An exception of type 'System.Reflection.TargetInvocationException' occurred while attempting to update from the database. The exception message is: 'Exception has been thrown by the target of an invocation.'.
Any ideas? I have tried doing this in an empty project also and still no dice!
Alex
You could try creating the Entity Data Model manually using the EdmGen.exe tool. Hopefully that will give a bit more information about the error.
Try turning on the include exception faults behaviour
namespace DataService
{
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class mydataservice : DataService<DataContext>
{
blah blah
I had similar issue. Look for similar names and missing mapping of forgen keys
I have had the same exeption, in my case it was my db(MySql) that had a table without a primary key, I just added a column "ID" and made it the primary key and voila! the exeption was gone :)

Convert string to GUID in Actionscript 3

I'm retrieving an GUID from a webservice with Flex.
With this GUID i have to retrieve an Username from the webservice.
The output gives me a "The key supplied is invalid. It must be of type System.Guid."
I looked everywhere for a solution, but I can't find the right answer.
Anyone?
Thanks!
edited: Is there a way to convert a string to a GUID in AS3?
I don't think you'll need to do this on the client. The problem is that you are sending a string to the server and that it requires an instance of System.Guid there and not a string. You can pass the string to the constructor of System.Guid to create a valid guid from the given string.

ASP.NET MVC: How to view query executed by SaveChanges (on the ADO.NET Entity Data Model)

When trying to add a few items to the database I'm getting this error:
UpdateException was unhandled by user code
An error occurred while updating the entries. See the InnerException for details.
The InnerException contains this:
{"Column count doesn't match value count at row 1"}
I can't see anything wrong with the objects I'm trying to add, all the required values are filled.
Is there any way of viewing the query that causes the problem?
The method's code, if required:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult LaadVerrichtingenIn() {
int[] intArray = Array.ConvertAll<String, int>(Request.Form["selectedObjects"].Split(','), new Converter<String, int>(Convert.ToInt32));
List<Verrichting> gekozenVerrichtingen = new List<Verrichting>();
foreach(int i in intArray){
base._entities.AddToVerrichtingSet(((Dictionary<int, Verrichting>)Session["ingelezenVerrichtingen"])[i]);
gekozenVerrichtingen.Add(((Dictionary<int, Verrichting>)Session["ingelezenVerrichtingen"])[i]);
}
Session["ingelezenVerrichtingen"] = null;
base._entities.SaveChanges(); //Exception occurs here
return View("IngeladenVerrichtingen");
}
base._entities is an ADO.NET Entity Data Model.
Thanks
I'm not sure if there's a 'neater' way to do this with the Entity Framework, but if you're using SQL Server then I'd generally use the SQL Server Profiler to read the queries being executed against the server. If you're using a different database then there may be an equivalent - in any case it would probably be helpful if you let us know.
If you're using MySQL > 5.0.37 it has new query profiler functionality - this should be able to show you the queries being sent.
SQL server profiler will work fine if you're using SQL Server. Within the Entity Framework, you can use the ToTraceString method.
I've just come across the same problem while inserting data using the Entity Framework and MySQL. My hunch is, since I'm using double values, that the decimal separator "," is being misinterpreted as a field separator. I upgraded to Connector version 6.1.0, but still no luck. Maybe this is also going on in your case.
Check out this bug report.
BTW, I found that the following line of code works around the problem:
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

Resources