sapiens/SqlFu

It seems that InsertedId doesn't get set its internal _value

Closed this issue · 5 comments

The problem I am facing is the following scenario:
A table I am running a db.Insert(T myPoco) for has a primary key being a Guid (UniqueIdentifier column).
An insert itself works flawlessly.
The problem starts when I attempt to verify an insert truly happened.
I believe I should use the following to check that:
InsertedId inserted = db.Insert(myPoco);
if(inserted.GetInsertedId<Guid>().Equals(Guid.Empty))

inserted.GetInsertedId<Guid> is null. I checked other types - Int32, object - all return null.

This is happening for a newest nuget package.
I used to verify this in previous SqlFu versions by checking LastInsertedIs.IsEmpty() property but that is no longer available. Ideally, I would like to have the same functionality in version 4 of SqlFu.
How can I achieve that?

Did you tell SqlFu which is the PK column? I think this is why it returns a null. I'll think about a way to return some feedback if a key is not specified, so that you have some confirmation about the insert

I tried researching on how to do that part. I could not find anything to declare a PK for my table. I believe this should be available somewhere within ConfigureTableForPoCo() method but I failed getting it set there.
I also researched if there are any class attributes left to decorate either a class property as PK or a class to inform which property acts as a PK. I could not find it there too.

Ok, fixed the issue and updated the readme with what you need. Ver 4.0.2 should appear on nuget soon.

Thank you.

Just so I understand: IsAutoIncremented() method for fields inside ConfigureTableForPoco() only works for Identity columns, correct?
I tried setting this for my Guid PK column and as I expected an insert statement failed because it omitted that column.
Is there any method I can use to decorate a class property as PK?

This should do the trick

d.Property(f => f.Id).IgnoreAtWriting()