MySQL的subsonic 3.0.0.4没有返回最后插入ID的活动记录模板
-
30-09-2019 - |
题
复制错误的步骤:
创建表格人(person_id int(11)不是null auto_increment,firstName varchar(20)默认为null,lastName varchar(20)默认为null,age int(11)默认'0',primary键(person_id)egine = innodb auto_increment = inodb auto_increment = inodb auto_increment = 36默认charset = latin1
插入人(firstName,lastName,age)值('myname',null,null); select last_insert_id()作为newid
Person personObject = new Person();
personObject.Firstname= "myname";
personObject.Add();
Response.Write(personObject.PersonId);
输出为“ 0'
解决方案
这不是一个错误,而是如果您更改列和表格的命名约定 - > topascalcase,可能会发生错误。默认情况下,按照MySQL数据库定义的方式复制了列/表名称。这使这个丑陋
原来的
person personObject = new person()
personObject .person_id = 1;
personObject .first_name = "hello";
personObject .Save();
我喜欢发生的事情
Person personObject = new Person()
personObject.PersonId = 1;
personObject.FirstName = "hello";
personObject.Save();
在更改默认模板以使用亚音速级供应器类生成以下名称后,将有两个(〜3,现在不记得)到亚音速内核。
必须更改更新/插入所需的属性的反射示例:
//from
item.GetType().GetProperty(tbl.PrimaryKey.Name);
//to
item.GetType().GetProperty(Inflector.ToPascalCase(tbl.PrimaryKey.Name));
执行插入示例时,应将列名返回其原始属性:
//from
GetColumn(key)
//to
GetColumn(Inflector.AddUnderscores(key))
不隶属于 StackOverflow