how does Reference attribure work?

Oct 14, 2011 at 12:54 PM

I'm trying to understand how the ORM work, and I have a question. For example I have some business objects in my software (model layer)

// business objects

public class BO1
{
  public float f_1;
  public float f_2;
  public float f_3;
}

public class BO2
{
  public BO1[] a = new BO1[5];
  public BO1[] b = new BO1[5];
  public BO1 c   = new BO1();
}

Now I want to store BO2 into the database (DAL layer). So, I should create appropriate tables for these business objects. It is clear for mew how to describe BO1 table:

// DB tables

[Entity(KeyScheme.Identity)]
public class TableBO1
{
  [Field(IsPrimaryKey = true)]
  public int id { get; set; }

  [Field] public double f_1 { get; set; }
  [Field] public double f_2 { get; set; }
  [Field] public double f_3 { get; set; }
}

But I do not understand how to create table for BO2. If I had only one BO1 array into BO2, I would have included one extra field into TableBO1 like

[Field]public int id_bo2 {get; set;}

and describe BO2 table like

 

[Entity(KeyScheme.Identity)]
public class TableBO2
{
  [Field(IsPrimaryKey = true)]
  public int id { get; set; }

  [Reference(typeof(BO1), "id_bo2", Autofill = true)]
  public BO1[] bo1_list { get; set; }
}

but what to do with second array 'b' and 'c' property in BO2?

Coordinator
Oct 14, 2011 at 9:38 PM

I'm not certain I understand your schema.  It looks like you have a 1:many relationship, but you're saying it's with three fields (1:n, 1:n and 1:1)?  I'll have to do a quick test to make sure I understand myself exactly how that would work.

Oct 17, 2011 at 11:53 AM

I have two sets of sensors which measure the same parameters but by two different ways. So, I read each set of sensors five times and obtain BO2.a[5] and BO2.b[5]. Using these data I calculate BO2.c array. And all these data I want to store into the database. I'm trying to understand is there any simple way to deal with the ORM and my database schema or I should do all these things manually.