Sam wrote:
Here is what I am trying to do:
MyEnity entity = new MyEntity(//GUID of Me);
Debug.Assert(entity.Name == "Me") //passes which means the entity was correctly fetched;
entity.Name = "NewName";
entity.Save()//throws error:
"The entity 'MyEntity' doesn't have a PK defined. The update query will therefore affect all entities in the table(s), not just this entity. Please define a Primary Key field in the designer for this entity."
However in the designer and database the PK is set (to a GUID).
Even stranger is that Delete() works!
So if I replace Save() with Delete() the record is correctly deleted. This seems like a fairly major bug (unless I am missing something stupid). Any ideas of what I can do?
I have some unittests which use an entity with a PK of GUID, and which work fine, so I'd like you to check the EntityFieldFactory.cs file and go to the line where the PK field is created for that entity. The line should look like:
fieldToReturn = new EntityField("ProductId", typeof(System.Guid), "ProductEntity", false, TypeDefaultValue.GetDefaultValue(typeof(System.Guid)), @"dbo", "Product", "ProductID", false, (int)SqlDbType.UniqueIdentifier, 0, 0, 0, true, false, "", false, null, typeof(System.Guid), (int)fieldIndex);
where the true after 0, 0, 0 is the flag for PK/FK. (as you will notice from the intellisense tooltip)
Could you check that for me please?
my testcode:
[Test]
public void SaveUpdateProduct()
{
ProductEntity p = EntityCreator.CreateNewProduct(1);
p.TestRunId = _testRunID;
Assert.IsTrue(p.Save());
ProductEntity fetchedP = new ProductEntity(p.ProductId);
Assert.AreEqual(EntityState.Fetched, fetchedP.Fields.State);
fetchedP.FullDescription += "lalala";
Assert.IsTrue(fetchedP.Save());
}
ProductId is a guid.