One Class in two hasmany relations

Aug 9, 2008 at 9:04 PM

Hello,
can DbEntry handle such a situation:

public class address
{
public string Name{get;set}
..
}

public class User
{
...
public HasMany<Address> Addresses{get;set;}

...

}

public class SomeClass
{
public HasMany<Address> Addresses{get; set;}
...
}

Coordinator
Aug 10, 2008 at 12:39 AM
Edited Aug 10, 2008 at 12:39 AM
Yes, it can handle it. But remember that:
  1. relation object must inherits from DbObjectModel
  2. HasMany and BelongsTo must paired.

So your classes should be:

public abstract class Address : DbObjectModel<Address>
{
    public abstract string Name{ get; set; }

    [BelongsTo]
    public abstract User user { get; set; }

    [BelongsTo]
    public abstract SomeClass some { get; set; }
    ...
}

public abstract class User : DbObjectModel<User>
{
    ...
    [HasMany]
    public abstract IList<Address> Addresses{ get; set; }
    ...
}

public abstract class SomeClass : DbObjectModel<SomeClass>
{
    ...
    [HasMany]
    public abstract IList<Address> Addresses { get; set; }
    ...
}

Aug 10, 2008 at 11:16 AM
Hello,
thx.
Isn't there a way without the BelongsTo because it won't work if the Address is in a Shared Assembly and the other classes in different "Modules (=Assemblies)" of my applicaiton who have a reference to the shared one.
Coordinator
Aug 10, 2008 at 4:10 PM
Sorry, There must has BelongsTo.
And I think all the db model should in the same assembly.