简体   繁体   English

在Fluent API中具有常量的外键

[英]Foreign key with constant in Fluent API

I need to load a reqired:many relationship from database. 我需要从数据库加载一个reqired:many关系。 Now my problem is, that the the key of the related table consists of three keys: 现在我的问题是,相关表的键包含三个键:

public partial class EnumValue
{
    [Key]
    [Column(Order = 0)]
    [StringLength(14)]
    public string EnumGroup { get; set; }

    [Key]
    [Column(Order = 1)]
    public byte EnumId { get; set; }

    [Key]
    [Column(Order = 2)]
    [StringLength(3)]
    public string Language { get; set; }

    [StringLength(50)]
    public string Description { get; set; }

}

In my other object I have only one property to fill the foreign key, the other parts are constants specific for this object. 在我的另一个对象中,我只有一个属性来填充外键,其他部分是特定于此对象的常量。
I tried to build the relations in EF6, but can't get it to work with model builder and the Fluent API using constants instead of properties: 我尝试在EF6中构建关系,但无法使用常量而不是属性来使用模型构建器和Fluent API:

modelBuilder.Entity<SupplierCondition>()                
    .HasRequired(t => t.ConditionTypeLookupRef)
    .WithMany()
    .HasForeignKey(t => new { "PArt", t.ConditionType, "EN" });

How can I pass constants as a value for a foreign key in Fluent API? 如何在Fluent API中将常量作为外键的值传递?

You can't use there const values because there isn't assign any value, you inform fluent API, which property refers to another table, when you pass "text", or 2, or new List(), it won't work they aren't properties, i think you can divide it to three tables, and use it as tags. 你不能使用const值,因为没有分配任何值,你通知fluent API,哪个属性引用另一个表,当你传递“text”,或2,或新的List(),它将无法工作它们不是属性,我认为你可以把它分成三个表,并用它作为标签。 But I can't see the bigger picture. 但我无法看到更大的图景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM