Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ InheritanceMappingAttribute代码属性_C#_Linq_Linq To Sql - Fatal编程技术网

C# LINQ InheritanceMappingAttribute代码属性

C# LINQ InheritanceMappingAttribute代码属性,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,InheritanceMappingAttributeatribute的code属性的用途是什么? 文档说明它与IsDiscriminator属性相关。但是,我也不知道IsDiscriminator属性 我正在读这个例子: public enum ShapeType { Square = 0, Circle = 1 } [Table(Name = "Shape")] [InheritanceMapping(Code = ShapeType.Square, Type = typeof(Sq

InheritanceMappingAttribute
atribute的
code
属性的用途是什么? 文档说明它与
IsDiscriminator
属性相关。但是,我也不知道
IsDiscriminator
属性

我正在读这个例子:

public enum ShapeType
{
    Square = 0, Circle = 1
}
[Table(Name = "Shape")]
[InheritanceMapping(Code = ShapeType.Square, Type = typeof(Square),
    IsDefault = true)]
[InheritanceMapping(Code = ShapeType.Circle, Type = typeof(Circle))]

abstract public class Shape
{
    [Column(IsDiscriminator = true)]
    public ShapeType ShapeType = 0;
}

public class Square : Shape
{
    [Column]
    public int Side = 0;
}
public class Circle : Shape
{
    [Column]
    public int Radius = 0;
}
就我而言,我有三个表,
个人
客户
职员
。三类人(摘要)、
客户
工作人员
。也就是说,在
Person
表中,是
Client
functional
之间的公共数据。在
客户机
表中是
客户机
的数据。在
职员
表中是
职员
的数据


在这种情况下如何配置映射?

使用EF6,您不必配置映射。只需创建类,其余的就由EF完成

public abstract class Person
{
    public int Id { get; set; }
}

[Table("Clients")]
public class Client : Person
{
}

[Table("Functionaries")]
public class Functionary : Person
{
}
EF创建3个表并设置关系

添加类型

context.Persons.Add(new Client());
context.Persons.Add(new Functionary());
您可以使用

Persons.OfType<Client>()
Persons.OfType()

使用EF6,您不必配置映射。只需创建类,其余的就由EF完成

public abstract class Person
{
    public int Id { get; set; }
}

[Table("Clients")]
public class Client : Person
{
}

[Table("Functionaries")]
public class Functionary : Person
{
}
EF创建3个表并设置关系

添加类型

context.Persons.Add(new Client());
context.Persons.Add(new Functionary());
您可以使用

Persons.OfType<Client>()
Persons.OfType()