Documentation - string primary key
If you have a string for a primary key, like this:
[PrimaryKey("Id", AutoIncrement = false)]
public class MyRecord
{
public string Id { get; set; }
//...
}
some operations will interpret your id as a SQL statement. For example:
_db.Delete<MyRecord>(id); // throws a sql exception
It would be nice to document that a string key may need to be cast to an object in order for the right method overload to be called:
_db.Delete<MyRecord>((object)id);
Hi, it's possible to set a string as primary key? i've been trying but i didn't figured it out. The way you do doesn't work.
[PrimaryKey("Id", AutoIncrement = false)] public class MyRecord { public string Code { get; set; } //... }
MyRecord t= new MyRecord() t.Code = "xx"; _db.Update(t); // throws a sql exception Insert no problem,but update PrimaryKey Exception。
Fix method NPoco.TableInfo public static TableInfo FromPoco(Type t)
//Add New Code Fix PrimaryKey Exception
if (tableInfo.PrimaryKey.Contains("false"))
{
tableInfo.AutoIncrement = false;
}
//新增修正代码
tableInfo.PrimaryKey = tableInfo.PrimaryKey.Replace(",AutoIncrement=false", "");
return tableInfo;