本文介绍了多个主键 - ORMlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建的数据库,为我的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),
约束`fk_Cultural_activity_activity1`
外键(`City_Id`,`activity_Id`)
参考`Tourist_Guide`.`activity`(`City_Id`,`activity_Id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB的;
你能不能,请告诉我如何将这些表映射到类(这个类应该是什么样子),是,即使可能吗?
解决方案
公共类的OrderDetail
{
公共字符串ID {{返回this.OrderId +/+ this.ProductId; }}
公众诠释订单ID {获得;组; }
公众诠释的ProductId {获得;组; }
公共小数单价{获得;组; }
公共短量{获得;组; }
公共双重优惠{获得;组; }
}
https://github.com/ServiceStack/ServiceStack.OrmLite/#limitations
I created database, for my android app, witch has 16 tables. I want to use ORMlite mapping. The problem is that I didn't find examples where you have composite id(Multiple primary keys). For example I have table:
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;
Can you, please, tell me how to map this table to class(how this class should look like), is that even possible?
解决方案
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
这篇关于多个主键 - ORMlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!