mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update Oracle
This commit is contained in:
parent
2add84b3f8
commit
52b62241c5
@ -64,42 +64,182 @@ namespace OrmTest
|
||||
OrderId=0,
|
||||
Price=1,
|
||||
ItemId=1
|
||||
},
|
||||
new OrderItem(){
|
||||
CreateTime=DateTime.Now,
|
||||
OrderId=0,
|
||||
Price=2,
|
||||
ItemId=2
|
||||
}
|
||||
}
|
||||
})
|
||||
.AddSubList(it => it.Items.First().OrderId).ExecuteReturnPrimaryKey();
|
||||
db.CodeFirst.InitTables<SubInsertTest, SubInsertTestItem, SubInsertTestItem1, SubInsertTestItem2>();
|
||||
Console.WriteLine("SubInsert Start2");
|
||||
db.Insertable(new List<SubInsertTest>() {
|
||||
new SubInsertTest()
|
||||
|
||||
|
||||
SubNoIdentity(db);
|
||||
SubIdentity(db);
|
||||
Console.WriteLine("#### Insertable End ####");
|
||||
}
|
||||
|
||||
private static void SubNoIdentity(SqlSugarClient db)
|
||||
{
|
||||
Name="aa",
|
||||
SubInsertTestItem1=new SubInsertTestItem1() {
|
||||
a="nn"
|
||||
},
|
||||
SubInsertTestItem=new SubInsertTestItem()
|
||||
db.CodeFirst.InitTables<Country, Province, City>();
|
||||
db.DbMaintenance.TruncateTable("Country");
|
||||
db.DbMaintenance.TruncateTable("Province");
|
||||
db.DbMaintenance.TruncateTable("City");
|
||||
db.Insertable(new List<Country>()
|
||||
{
|
||||
Name ="item" ,
|
||||
TestId=2
|
||||
new Country(){
|
||||
Id=1,
|
||||
Name="中国",
|
||||
Provinces=new List<Province>(){
|
||||
new Province{
|
||||
Id=1001,
|
||||
Name="江苏",
|
||||
citys=new List<City>(){
|
||||
new City(){ Id=1001001, Name="南通" },
|
||||
new City(){ Id=1001002, Name="南京" }
|
||||
}
|
||||
},
|
||||
new SubInsertTest()
|
||||
{
|
||||
Name="aa",
|
||||
SubInsertTestItem1=new SubInsertTestItem1() {
|
||||
a="nn"
|
||||
new Province{
|
||||
Id=1002,
|
||||
Name="上海",
|
||||
citys=new List<City>(){
|
||||
new City(){ Id=1002001, Name="徐汇" },
|
||||
new City(){ Id=1002002, Name="普陀" }
|
||||
}
|
||||
},
|
||||
SubInsertTestItem=new SubInsertTestItem()
|
||||
new Province{
|
||||
Id=1003,
|
||||
Name="北京",
|
||||
citys=new List<City>(){
|
||||
new City(){ Id=1003001, Name="北京A" },
|
||||
new City(){ Id=1003002, Name="北京B" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Country(){
|
||||
Name="美国",
|
||||
Id=2,
|
||||
Provinces=new List<Province>()
|
||||
{
|
||||
Name ="item" ,
|
||||
TestId=2
|
||||
new Province(){
|
||||
Name="美国小A",
|
||||
Id=20001
|
||||
},
|
||||
new Province(){
|
||||
Name="美国小b",
|
||||
Id=20002
|
||||
}
|
||||
}
|
||||
},
|
||||
new Country(){
|
||||
Name="英国",
|
||||
Id=3
|
||||
}
|
||||
})
|
||||
.AddSubList(it => new SubInsertTree()
|
||||
{
|
||||
Expression = it.Provinces.First().CountryId,
|
||||
ChildExpression = new List<SubInsertTree>() {
|
||||
new SubInsertTree(){
|
||||
Expression=it.Provinces.First().citys.First().ProvinceId
|
||||
}
|
||||
}
|
||||
})
|
||||
.AddSubList(it => it.SubInsertTestItem.TestId)
|
||||
.AddSubList(it => it.SubInsertTestItem1)
|
||||
.ExecuteReturnPrimaryKey();
|
||||
Console.WriteLine("#### Insertable End ####");
|
||||
|
||||
var list = db.Queryable<Country>()
|
||||
.Mapper(it => it.Provinces, it => it.Provinces.First().CountryId)
|
||||
.Mapper(it =>
|
||||
{
|
||||
foreach (var item in it.Provinces)
|
||||
{
|
||||
item.citys = db.Queryable<City>().Where(y => y.ProvinceId == item.Id).ToList();
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
private static void SubIdentity(SqlSugarClient db)
|
||||
{
|
||||
db.CodeFirst.InitTables<Country1, Province1, City1>();
|
||||
db.DbMaintenance.TruncateTable("Country1");
|
||||
db.DbMaintenance.TruncateTable("Province1");
|
||||
db.DbMaintenance.TruncateTable("City1");
|
||||
db.Insertable(new List<Country1>()
|
||||
{
|
||||
new Country1(){
|
||||
Id=1,
|
||||
Name="中国",
|
||||
Provinces=new List<Province1>(){
|
||||
new Province1{
|
||||
Id=1001,
|
||||
Name="江苏",
|
||||
citys=new List<City1>(){
|
||||
new City1(){ Id=1001001, Name="南通" },
|
||||
new City1(){ Id=1001002, Name="南京" }
|
||||
}
|
||||
},
|
||||
new Province1{
|
||||
Id=1002,
|
||||
Name="上海",
|
||||
citys=new List<City1>(){
|
||||
new City1(){ Id=1002001, Name="徐汇" },
|
||||
new City1(){ Id=1002002, Name="普陀" }
|
||||
}
|
||||
},
|
||||
new Province1{
|
||||
Id=1003,
|
||||
Name="北京",
|
||||
citys=new List<City1>(){
|
||||
new City1(){ Id=1003001, Name="北京A" },
|
||||
new City1(){ Id=1003002, Name="北京B" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Country1(){
|
||||
Name="美国",
|
||||
Id=2,
|
||||
Provinces=new List<Province1>()
|
||||
{
|
||||
new Province1(){
|
||||
Name="美国小A",
|
||||
Id=20001
|
||||
},
|
||||
new Province1(){
|
||||
Name="美国小b",
|
||||
Id=20002
|
||||
}
|
||||
}
|
||||
},
|
||||
new Country1(){
|
||||
Name="英国",
|
||||
Id=3
|
||||
}
|
||||
})
|
||||
.AddSubList(it => new SubInsertTree()
|
||||
{
|
||||
Expression = it.Provinces.First().CountryId,
|
||||
ChildExpression = new List<SubInsertTree>() {
|
||||
new SubInsertTree(){
|
||||
Expression=it.Provinces.First().citys.First().ProvinceId
|
||||
}
|
||||
}
|
||||
})
|
||||
.ExecuteReturnPrimaryKey();
|
||||
|
||||
var list = db.Queryable<Country1>()
|
||||
.Mapper(it => it.Provinces, it => it.Provinces.First().CountryId)
|
||||
.Mapper(it =>
|
||||
{
|
||||
foreach (var item in it.Provinces)
|
||||
{
|
||||
item.citys = db.Queryable<City1>().Where(y => y.ProvinceId == item.Id).ToList();
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,60 @@ namespace OrmTest
|
||||
public int xid { get; set; }
|
||||
public string a { get; set; }
|
||||
}
|
||||
public class Country
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<Province> Provinces { get; set; }
|
||||
}
|
||||
|
||||
public class Province
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int CountryId { get; set; }
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<City> citys { get; set; }
|
||||
}
|
||||
|
||||
public class City
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
public int Id { get; set; }
|
||||
public int ProvinceId { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class Country1
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, OracleSequenceName = "seq_id")]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<Province1> Provinces { get; set; }
|
||||
}
|
||||
|
||||
public class Province1
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, OracleSequenceName = "seq_id")]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int CountryId { get; set; }
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<City1> citys { get; set; }
|
||||
}
|
||||
|
||||
public class City1
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, OracleSequenceName ="seq_id")]
|
||||
public int Id { get; set; }
|
||||
public int ProvinceId { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ namespace SqlSugar
|
||||
|
||||
private bool IsIdEntity(EntityInfo entity)
|
||||
{
|
||||
return entity.Columns.Where(it => it.IsIdentity).Count() > 0;
|
||||
return entity.Columns.Where(it => it.IsIdentity||it.OracleSequenceName.HasValue()).Count() > 0;
|
||||
}
|
||||
|
||||
private void AddChildList(List<SubInsertTreeExpression> items, object insertObject, object pkValue)
|
||||
@ -183,6 +183,11 @@ namespace SqlSugar
|
||||
if (isIdentity)
|
||||
{
|
||||
id = this.Context.Insertable(insert).AS(tableName).ExecuteReturnIdentity();
|
||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle&&id==0)
|
||||
{
|
||||
var seqName=entityInfo.Columns.First(it => it.OracleSequenceName.HasValue())?.OracleSequenceName;
|
||||
id = this.Context.Ado.GetInt("select "+seqName+".currval from dual");
|
||||
}
|
||||
}
|
||||
var entity = entityList[i];
|
||||
var pk = GetPrimaryKey(entityInfo,entity, id);
|
||||
|
Loading…
Reference in New Issue
Block a user