我创建了数据库,对于我的Android应用程序,女巫有16个表.我想使用Ormlite映射.问题是我没有找到你有复合ID(多个主键)的例子.例如我有桌子:
CREATE table IF NOT EXISTS `Tourist_GuIDe`.`Cultural_activity` ( `City_ID` INT NOT NulL , `activity_ID` INT NOT NulL , `Cultural_activity_ID` INT NOT NulL auto_INCREMENT , `name_Of_Cultural_activity` VARCHAR(30) NOT NulL , PRIMARY KEY (`Cultural_activity_ID`, `City_ID`, `activity_ID`) , INDEX `fk_Cultural_activity_activity1` (`City_ID` ASC, `activity_ID` ASC) , CONSTRAINT `fk_Cultural_activity_activity1` FOREIGN KEY (`City_ID` , `activity_ID` ) REFERENCES `Tourist_GuIDe`.`activity` (`City_ID` , `activity_ID` ) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE = InnoDB;
请你告诉我如何将这个表映射到类(这个类应该如何),是否可能?
解决方法:
limitationsFor simplicity, and to be able to have the same POCO class persisted in db4o, memcached, redis or on the filesystem (i.e.
provIDers included in ServiceStack), each model must have a single
primary key, by convention Ormlite expects it to be ID although you
use [Alias(“DbFIEldname”)] attribute it map it to a column with a
different name or use the [PrimaryKey] attribute to tell Ormlite to
use a different property for the primary key.You can still SELECT from these tables, you will just be unable to
Workaround single Primary Key limitation
make use of APIs that rely on it, e.g. Update or Delete where the
filter is implIEd (i.e. not specifIEd), all the APIs that end with
ByID, etc.A potential workaround to support tables with multiple primary keys is
to create an auto generated ID property that returns a unique value
based on all the primary key fIElds, e.g:
public class OrderDetail{ public string ID { get { return this.OrderID + "/" + this.ProductID; } }public int OrderID { get; set; } public int ProductID { get; set; } public decimal UnitPrice { get; set; } public short Quantity { get; set; } public double discount { get; set; }}
https://github.com/ServiceStack/ServiceStack.OrmLite/#limitations
总结以上是内存溢出为你收集整理的android – 如何使用多个主键全部内容,希望文章能够帮你解决android – 如何使用多个主键所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)