使用fluentapi以编程方式指定表的外键 [英] specifying the foreign key to the table programmatically by using fluentapi

查看:188
本文介绍了使用fluentapi以编程方式指定表的外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你有什么可能使用实体分配一个foriegnkey表。

hi is there any possibility to assign a foriegnkey to table using entity ....

请看这个问题来澄清.. 如何使用linq为实体添加两个表的单个条目

pls see this question for clarification.. how do add a single entry for two tables using linq to entities

让我解释清楚.....

let me explain clearly.....

      i have a product table    product_id
                                product_name 
                                product_description
                                category_id


                                category table
                                category_id
                                category_name 

不幸的是,在创建表时,将category_id指定为外键是不可取的,将category_id作为列作为外键

unfortunately it is not posssible to specify the category_id as a foreign key at the time of creating table the entity table it self taken the category_id as a column not as a foreign key

所以..我想指定这一个作为外键所以..可以通过程序设计指定为外键
可以任何一个具有使用流畅的api指定外键的示例代码

so.. i want to specify this one as foreign key so.. is it possible to specify as a foreign key by programmatically can any one have sample code for specifying foreignkey using fluent api

推荐答案

如果您使用EntityFramework 4.1,可以使用 Fluent API ,它允许您指定密钥名称和其他关联属性。

If you're using EntityFramework 4.1, you can use the Fluent API, which allows you to specify key names and other association properties.

这篇关于使用fluentapi以编程方式指定表的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆