实体框架:设置外键属性
我们有一个大致如下所示的表:
CREATE TABLE Lockers
{
UserID int NOT NULL PRIMARY KEY (foreign key),
LockerStyleID int (foreign key),
NameplateID int (foreign key)
}
所有键都与其他表相关,但由于应用程序的分发方式,我们更容易将 ID 作为参数传递。 所以我们想要这样做:
Locker l = new Locker {
UserID = userID,
LockerStyleID = lockerStyleID,
NameplateID = nameplateID
};
entities.AddLocker(l);
我们可以在 LINQ-to-SQL 中完成,但不能在 EF 中完成?
We have a table that looks roughly like this:
CREATE TABLE Lockers
{
UserID int NOT NULL PRIMARY KEY (foreign key),
LockerStyleID int (foreign key),
NameplateID int (foreign key)
}
All of the keys relate to other tables, but because of the way the application is distributed, it's easier for us to pass along IDs as parameters. So we'd like to do this:
Locker l = new Locker {
UserID = userID,
LockerStyleID = lockerStyleID,
NameplateID = nameplateID
};
entities.AddLocker(l);
We could do it in LINQ-to-SQL, but not EF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(6)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这个缺失的功能似乎让很多人烦恼。
你必须这样做:
This missing feature seems to annoy a lot of people.
You have to do it like this: