obase社区Obase开发者QQ群:962698871
obase

欢迎查阅
OBASE帮助文档

对于显式关联型,我们可以直接通过ObjectSet添加关联对象也可以通过为关联引用设值或添加元素的方式添加关联对象,后一种方式与隐式关联型并无区别,可以参考新增关联一节,此处仅介绍通过ObjectSet添加,以下示例使用的模型为开始使用一章的高人斗法一节内容:

var context = new ClassAndTeacherContext();

//新增一个班级
var newclass = new Class
{
    Name = @"某某班"
};

//新两个增老师
var teacher1 = new Teacher {Name = "老师1"};
var teacher2 = new Teacher {Name = "老师2"};

//与第一个老师建立关联
var teaching1 = new Teaching
{
    Class = newclass,
    Teacher = teacher1,
    IsManage = true
};

//与第二个老师建立关联
var teaching2 = new Teaching
{
    Class = newclass,
    Teacher = teacher2,
    IsManage = false
};

//持久化
context.ClassTeachers.Attach(teaching1);
context.ClassTeachers.Attach(teaching2);
context.SaveChanges();

没有找到您需要的文档?

您还可以通过人工服务在线咨询,服务时间为每天上午9点至下午6点。

If you can't find required answer, get in touch with us online. We provide service from 9:00 to 18:00.

让编程成为一件快乐的事
现在开始