You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the DataObject to insert a row into a table that has a Guid PK. It works great with an incrementing Id. But once I switched to a Guid I can't get it to work.
I've tried setting the pk like this in the initialisation:
var userData = new DataObject("Users","Guid");
model.Guid = Guid.NewGuid();
userData.Insert(model);
But that doesn't work I get a sql error saying Guid cannot be null.
"Cannot insert the value NULL into column 'Guid', table 'Nancy.dbo.Users'; column does not allow nulls. INSERT fails."
What am I doing wrong?
Gus
ps: I found this code in DataRuntimeObject.cs which looks a bit dubious. See the "Id" bit.
public PropertyInfo GetPrimaryKey(string primaryKeyName)
{
if (_primaryKey == null)
{
var validProperties = GetValidProperties();
if (primaryKeyName != null) return validProperties.FirstOrDefault(p => p.Name == primaryKeyName);
_primaryKey = validProperties.FirstOrDefault(p => p.Name == "Id" ) ?? validProperties.First();
}
return _primaryKey;
}
The text was updated successfully, but these errors were encountered:
yes, thanks, it would be nice if it could handle GUID's because IDENTITY types are troublesome for me when it comes to merging databases. But I don't have a good enough grasp of the code to be able to enhance it.
Hi
I am trying to use the DataObject to insert a row into a table that has a Guid PK. It works great with an incrementing Id. But once I switched to a Guid I can't get it to work.
I've tried setting the pk like this in the initialisation:
var userData = new DataObject("Users","Guid");
model.Guid = Guid.NewGuid();
userData.Insert(model);
But that doesn't work I get a sql error saying Guid cannot be null.
"Cannot insert the value NULL into column 'Guid', table 'Nancy.dbo.Users'; column does not allow nulls. INSERT fails."
What am I doing wrong?
Gus
ps: I found this code in DataRuntimeObject.cs which looks a bit dubious. See the "Id" bit.
public PropertyInfo GetPrimaryKey(string primaryKeyName)
{
if (_primaryKey == null)
{
var validProperties = GetValidProperties();
if (primaryKeyName != null) return validProperties.FirstOrDefault(p => p.Name == primaryKeyName);
_primaryKey = validProperties.FirstOrDefault(p => p.Name == "Id" ) ?? validProperties.First();
}
The text was updated successfully, but these errors were encountered: