Fluent API中具有常数的外键 [英] Foreign key with constant in Fluent API

查看:80
本文介绍了Fluent API中具有常数的外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从数据库中加载一个reqired:many关系。现在我的问题是,相关表的键由三个键组成:

I need to load a reqired:many relationship from database. 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; }

}

在我的另一个对象中,我只有一个属性可以填充
我试图在EF6中建立关系,但无法使用常量而不是属性来与模型构建器和Fluent API一起使用:

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:

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

如何在Fluent API中将常量作为外键的值传递?

How can I pass constants as a value for a foreign key in Fluent API?

推荐答案

您不能在此处使用const值,因为没有分配任何值,您需要告知fluent API,该属性引用另一个表,何时您传递文本或2,或新的List(),它们不是属性,将不起作用,我认为您可以将其分为三个表,并将其用作标签。但是我看不到大局。

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. But I can't see the bigger picture.

这篇关于Fluent API中具有常数的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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