-
Notifications
You must be signed in to change notification settings - Fork 859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OneToMany 一对多,怎么添加数据? #46
Comments
var repo = orm.GetRepository<Tag>();
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true; //需要手工开启
var tag = new Tag {
Name = "testaddsublist",
Tags = new[] {
new Tag { Name = "sub1" },
new Tag { Name = "sub2" },
new Tag {
Name = "sub3",
Tags = new[] {
new Tag { Name = "sub3_01" }
}
}
}
};
repo.Insert(tag); 约定
|
var tag = new A { 请问大神 new A{} 是什么语法呀? |
笔误,已改正 级联保存机制:https://github.com/2881099/FreeSql/wiki/%e8%81%94%e7%ba%a7%e4%bf%9d%e5%ad%98 |
class School_grade
{
[Navigate("School_class_Id")]
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public string Grade { get; set; }
public int School_class_Id { get; set; }
public School_class School_class { get; set; }
public ICollection<School_class> aaaa { get; set; }
}
class School_class
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int aaaaSchool_gradeId { get; set; }
public string Class { get; set; }
//public School_grade School_Grade { get; set; }
} aaaa那一块,调试的时候说缺少这个字段,而且还是拼接固定值,请问这是必要的吗? |
级联保存分两种: 1、追加保存,即不处理已存在的数据 var repo = fsql.GetRepository<ProjectEnergyType>();
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true; //需要手工开启
repo.Insert(pe); 2、完整保存,会对比老数据计算出添加、修改、删除执行 var repo = fsql.GetRepository<ProjectEnergyType>();
repo.Insert(pe);
repo.SaveMany(item, "EnergyTypes"); //在现有的数据上保存,内部会和现有数据进行对比,计算出应该插入、更新、删除的子记录 |
刚刚没理解,现在好很多了,以 班级-年级 举例,单向存储的时候,我看到了可以存年级的时候存储子表的班级, |
而且我尚未理解您例子中的实体,为何要加虚方法关键字? |
只能一对多,多对多级联保存。
virutal 主要作为是延时加载的导航属性,跟级联保存没关系。 |
好的,非常感谢! |
还有一个问题,使用UseMonitorCommand只是成功的时候有SQL语句查看,但是SQL出错后,错误日志却只在vs输出框输出,如何让它在命令行打印日志? MonitorCommandExecuting = cmd => Console.WriteLine(cmd.CommandText)
MonitorCommandExecuted = (cmd, s) => Console.WriteLine(s) |
是 vs 得使用问题吗,弹出的异常窗口有一个设置 |
我找到问题了所在了,谢谢。 |
实体
The text was updated successfully, but these errors were encountered: