如何使用元组中的值作为对象之间的关系。 [英] How to use values in Tuples as Relations between objects.

查看:56
本文介绍了如何使用元组中的值作为对象之间的关系。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类MasterData,包含多个List<>物业,如下所示:



  &NBSP; &NBSP; &NBSP;公共列表<实体>实体=新列表<实体>();

  &NBSP; &NBSP; &NBSP; public List< Tuple< Entity,Entity>>关系=新列表<元组<实体,实体>>();

  &NBSP; &NBSP; &NBSP;公共列表< AgeComponent> AgeComponents = new List< AgeComponent>();

public List< GradeComponent> GradeComponents = new List< GradeComponent>();



其中Component类型定义为:



&NBSP; &NBSP;公共抽象类组件

  &NBSP; {

  &NBSP; &NBSP; &NBSP; public long EntityId {get;组; } //此ID对应于GradeValue实体对象的ID或学生的实体ID。

  &NBSP; }


如下:



公共类AgeComponent:组件

  ; &NBSP; {

  &NBSP; &NBSP; &NBSP; public double Value {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; public bool IsMissing {get;组; }¥b $ b  &NBSP; b

或b

公共类GradeComponent:组件

  &NBSP; {

  &NBSP; &NBSP; &NBSP; public double Value {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; public bool IsMissing {get;组; }¥b $ b  &NBSP; }


和实体类型定义为:



公共抽象类实体

  &NBSP; {

  &NBSP; &NBSP; &NBSP; public long Id {get;组; }


  &NBSP; &NBSP; &NBSP; public string Tag {get;组; } //实体类型的名称,例如"学生"类型或"教师"或"GradeValue"

  &NBSP; }


有学生,教师和GradeValue的实体,如下:
$


公共班学生:实体

  &NBSP; {

  &NBSP; }


公共课老师:实体

  &NBSP; {

  &NBSP; }


公共类GradeValue:实体

  &NBSP; {

  &NBSP; }


关系列表<>将不同的,相关的实体的ID设置为新的元组。



我需要加载List<>所有学生ID,他们的年龄和成绩,以及他们的教师ID在一个对象中定义为:



公共班学生数据 

{

public long studentId {get;组; }
公共双倍年龄{get;组; }
公共双等级{get;组; }
public long teacherId {get;组;例如,MasterData对象可以像这样填充:



entityIdCounter = 1;}
}



教师教导=新教师()

{

Id = entityIdCounter ++,

  &NBSP; &NBSP; &NBSP; Tag =" teacher"

};
$
MasterData.Entities.Add(示教);



学生student = new Student()

{

Id = entityIdCounter ++,

  &NBSP; &NBSP; &NBSP; Tag =" student"

};

MasterData.Entities.Add(student);
$


MasterData .Relations.Add(new Tuple< Entity,Entity>(teach,student));
$


AgeComponent age = new AgeComponent()

{

EntityId = student.Id,

  &NBSP; &NBSP; &NBSP;值= 10

};
$


MasterData.AgeComponents.Add(年龄);



GradeValue值=新GradeValue()

{

Id = entityIdCounter ++,

  &NBSP; &NBSP; &NBSP; Tag =" measurement"

};

MasterData.Entities.Add(valu);

$
MasterData .Relations.Add(new Tuple< Entity,Entity>(student,valu));



考虑到所有这些,请给我一些关于如何使用用于加载未丢失学生ID的值的关系,以及关系列表中的对应教师ID<>并且学生ID和成绩
值ID之间存在关联,AgeComponent通过实体ID与学生相关。

解决方案

你好JimNickFL,


>>鉴于所有这些,请给我一些关于如何使用关系加载学生值的建议我不缺少ID,并且关系列表中有相应的教师ID<>并且学生
Id和成绩价值ID之间存在关联,而AgeComponent通过实体ID与学生相关。


根据你的描述,我不确定你想从Relations实例中检索什么结果。你能详细描述一下吗?如果想知道实体的类型,可以使用以下方法。

 foreach(Master数据中的元组<实体,实体>项目)
{
if(item.Item2 is Student)
{
Student st =(Student)item.Item2;
}
}

祝你好运,


Cole Wu


I have a class, MasterData, containing several List<> properties, as seen below:

        public List<Entity> Entities = new List<Entity>();
        public List<Tuple<Entity, Entity>> Relations = new List<Tuple<Entity, Entity>>();
        public List<AgeComponent> AgeComponents = new List<AgeComponent>();
public List<GradeComponent> GradeComponents = new List<GradeComponent>();

Where a Component type is defined as:

    public abstract class Component
    {
        public long EntityId { get; set; } // This ID corresponds to a GradeValue Entity object's ID OR a Student's Entity ID.
    }

such as:

public class AgeComponent : Component
    {
        public double Value { get; set; }
        public bool IsMissing { get; set; }
    }

or

public class GradeComponent : Component
    {
        public double Value { get; set; }
        public bool IsMissing { get; set; }
    }

and an Entity type is defined as:

public abstract class Entity
    {
        public long Id { get; set; }

        public string Tag { get; set; } // The name of the Entity type, such as "Student" or "Teacher" or "GradeValue"
    }

There are Entities for Student, Teacher, and GradeValue, like so:

public class Student : Entity
    {
    }

public class Teacher : Entity
    {
    }

public class GradeValue : Entity
    {
    }

The Relations List<> sets the Id's of different, related, Entities to a new Tuple.

I need to load a List<> of all Student Id's, their ages and grades, and their Teacher's Id's in an object defined as:

public class StudentData 
{
public long studentId { get; set; }
public double age{ get; set; }
public double grade{ get; set; }
public long teacherId { get; set; }
}
For example, the MasterData object could be filled like this:

entityIdCounter = 1;
Teacher teach = new Teacher()
{
Id = entityIdCounter++,
        Tag="teacher"
};
MasterData.Entities.Add(teach);

Student student = new Student()
{
Id = entityIdCounter++,
        Tag = "student"
};
MasterData.Entities.Add(student);

MasterData.Relations.Add(new Tuple<Entity, Entity>(teach, student));

AgeComponent age = new AgeComponent()
{
EntityId = student.Id,
        Value = 10
};

MasterData.AgeComponents.Add(age);

GradeValue valu = new GradeValue()
{
Id=entityIdCounter++,
        Tag="measurement"
};
MasterData.Entities.Add(valu);

MasterData.Relations.Add(new Tuple<Entity, Entity>(student, valu));

Given all of that, please give me some suggestions on how to use the Relations to load values where the Student Id is not missing, and there is a corresponding Teacher Id in the Relations List<> and there is a Relation between the Student Id and the Grade Value ID and the AgeComponent is related to the Student by way of an Entity Id.

解决方案

Hi JimNickFL,

>>Given all of that, please give me some suggestions on how to use the Relations to load values where the Student Id is not missing, and there is a corresponding Teacher Id in the Relations List<> and there is a Relation between the Student Id and the Grade Value ID and the AgeComponent is related to the Student by way of an Entity Id.

According to your description, I'm not sure what the result you want to retrieve from Relations instance. Could you please describe it in detail. If want to know the type of Entity, you could use the following method.

foreach (Tuple<Entity, Entity> item in MasterData.Relations)
            {
                if (item.Item2 is Student)
                {
                   Student st = (Student)item.Item2;
                }
            }

Best regards,

Cole Wu


这篇关于如何使用元组中的值作为对象之间的关系。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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