开发者

Setting a foreign key value using Entity Framework .NET 3.5?

My table:

Employee
--------
Name
Age
Role int (foreign key)

How can I assign a te开发者_运维技巧xtbox value to the Role column?

In Entity Framework 4 I would go:

Employee x = new Employee()
x.Role = textBox1.Text;

It seems I don't have the Role columns available to me.

Thanks.


EF1 is not that much different on the code side to EF4. There should be two properties:

  • Role
  • RoleReference

In your case, you'd be setting primary key value of the latter one to avoid loading the whole Role entity.

So if you really don't see any of these, then your project maybe didn't compile and you're still looking at some older version of it, that doesn't have the Role relationship.


You should have a Role property available. Check your relationship between Employee and Role. Rebuild the project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜