Server-generated keys and server-generated values are not supported by SQL Server Compact
So I understand that CE doesn't support server-generate values - thats alright, I am providing my own with this code...
public static class ExtensionMethods
{
public static TResult NextId<TSource, TResult>(this ObjectSet<TSource> table, Expression<Func<TSource, TResult>> selector)
where TSource : class
{
TResult lastId = table.Any() ? table.Max(selector) : default(TResult);
if (lastId is int)
lastId = (TResult)(object)(((int)(object)lastId) + 1);
return lastId;
}
}
private void AddProperty()
{
Property p = new Property();
entities.AddToProperties(new Property()
{
ID = entities.Properties.NextId(u => u.ID),
AgentName = "Agent Name",
Address = "New Property",
AuctioneerName = "Auctioneer Name",
SaleTitle = "Sales Title",
DateOfAuction = null,
ReservePrice = null,
CurrentBid = null,
PreviousBid = null,
});
entities.SaveChanges();
BindData();
}
Only issue is that this doesn't fix the problem when I think it should. I have 2 tables. One called Property, the other called Image. The ID of both is set to primary key, unique yes, and identity to false. I can't see what I am doing wrong to get this error still, all other fields are set to nullable but 开发者_运维问答I don't think this has anything to do with this error...
Found the solution, it turned out my Identity value couldn't be edited manually, I had to re-generate the database creating it through the model first.
精彩评论