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
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 ---
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
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 ---