West Wind Toolkit for .NET
UpdateEntity Expecting Key as String
Gravatar is a globally recognized avatar based on your email address. UpdateEntity Expecting Key as String
  Craig Tucker
  All
  Mar 12, 2024 @ 10:33am

Hi Rick, How do I pass a Guid into the UpdateEntity method when the method is expecting a string?

I converted objParticipant.ParticipantID_GUI to a string to work with UpdateEntity but is throwing an object reference error. The field in the table is a uniqueidentifier (newid()).

qmmSQL.Db.UpdateEntity(objParticipant, "[Wellness].[dbo].[Participant]", objParticipant.ParticipantID_GUI, "ParticipantID_GUI");

Thank you, Craig

Gravatar is a globally recognized avatar based on your email address. re: UpdateEntity Expecting Key as String
  Rick Strahl
  Craig Tucker
  Mar 12, 2024 @ 10:52am

The signature is:

public virtual bool UpdateEntity(object entity, string table, string keyField, string propertiesToSkip = null)

You need to pass the name of the field - it'll pick the key out of the entity.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: UpdateEntity Expecting Key as String
  Craig Tucker
  Rick Strahl
  Mar 13, 2024 @ 06:46am

SMH, brain fart, duh - Thanks Rick...

I have another related question...

In the InsertEntity, is there a way to get the GUID id since the table primary key does not use identity but uses newid() as unique identifier guid?

For example, the following InsertEntity works but returns a blank string instead of the generated guidId.

wellnessParticipantParticipationID = Convert.ToString(qmmSQL.Db.InsertEntity(objParticipant, "[Wellness].[dbo].[Participant_TBL]", "PK_Participant_ID_GUI"));

Thanks, Craig

Gravatar is a globally recognized avatar based on your email address. re: UpdateEntity Expecting Key as String
  Rick Strahl
  Craig Tucker
  Mar 13, 2024 @ 01:00pm
public object InsertEntity(object entity, string table, string propertiesToSkip = null, bool returnIdentityKey = true)

Pass returnIdentityKey: true.

Result will be an object and you have to cast it to your data type. I think a Guid comes back as a Guid object.

+++ Rick ---

© 1996-2024