在将navagation属性用于复杂类型时,使用可插入约定来更改外键的默认属性名称。

编程入门 行业动态 更新时间:2024-10-26 11:25:17
本文介绍了在将navagation属性用于复杂类型时,使用可插入约定来更改外键的默认属性名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个现有的数据库我想用和Entity Framework Code First。基于这个文章( blogs.msdn/b/adonet/archive/2011/01/10/ef-feature-ctp5-pluggable-conventions.aspx?wa=wsignin1.0 ) I我正在尝试更改默认约定。我已成功更改它以使用单数表名称,但现在想要调整导航属性的行为方式。

看下面的例子,我想能够在数据库中有一个名为'HomeAddressId'的字段这是Person表中的外键到Address表中的主键。如果我添加名为HomeAddressId的主要属性,它可以工作,但我希望能够删除它。删除后,它将采用HomeAddressAddressID的名称。

如何更改约定以使用PropertyName +" ID"?

How can I change the conventions to use the PropertyName + "ID"?

感谢您的帮助......

Thank you for your help...

public class 人员< { public int PersonId { get ; set ; } public string FirstName { get ; set ; } public string LastName { get ; set ; } public 虚拟 地址 HomeAddress { get ; set ; } }

public class Person { public int PersonId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public virtual Address HomeAddress { get; set; } }

public class 地址 { public int AddressId { get ; set ;} public string 地址1 { get ; set ; } public string City { get ; set ; } public string 状态{ get ; set ; } public string Zip { get ; set ; } }

public class Address { public int AddressId { get; set;} public string Address1 { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } }

推荐答案

Hi William,

Hi William,

这在CTP5中预览的约定功能中是不可能的(关系的配置仍然是内部的。)而不是使用约定,你可以编写一些代码来反映您的类型,查找引用属性并使用反射来调用Fluent API。由于Fluent API中的所有通用方法,它将是混乱的代码,但它应该是可能的。

This isn't possible in the convention functionality that was previewed in CTP5 (configuration of relationships was still internal). Rather than using conventions, you could write some code to reflect over your types, look for reference properties and use reflection to call the Fluent API. It will be messy code because of all the generic methods in the Fluent API, but it should be possible.

~Rowan

更多推荐

在将navagation属性用于复杂类型时,使用可插入约定来更改外键的默认属性名称。

本文发布于:2023-11-12 00:57:25,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   名称   类型   navagation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!