Entity Inheritance

47 views
Skip to first unread message

Mark N

unread,
Oct 23, 2013, 1:49:01 PM10/23/13
to brightsta...@googlegroups.com
Suppose I have two Entity types, NodeBase and FooNode, with interfaces INodeBase and IFooNode respectively.  In the interface definition, I can define something like this:

    [Entity]
    public interface INodeBase
    {
    }

    [Entity]
    public interface IFooNode
    {
    }

The generated classes will then look something like this:

    public partial class NodeBase : BrightstarEntityObject, INodeBase {...}
    public partial class FooNode: BrightstarEntityObject, IFooNode {...}

What I want is to apply some label or annotation to the interface definition, to specify that class FooNode inherits from class NodeBase instead of BrightstarEntityObject.

I wasn't able to find anything in the documentation about this.   Perhaps a good place to have the annotation would be a parameter of the Entity attribute constructor.  I can probably change the text template to handle this, but text templates are a new concept to me and I'm not sure how to debug them or step through them.  Also, I'm not aware whether this will cause any problems in the database itself or the entity framework layer.  

Thank you for your help.

Mark N

unread,
Oct 24, 2013, 2:56:09 AM10/24/13
to brightsta...@googlegroups.com
My post didn't show up on the group site when I posted via e-mail, so I'll try this again.  Apologies if this shows up twice.

I was able to edit the .tt file using this VS extension: http://visualstudiogallery.msdn.microsoft.com/b0e2dde6-5408-42c2-bc92-ac36942bbee9

If anyone is interested, here is the .tt file after my simple modifications (do a diff to see what changed).

And the additional attribute file:

    public class InheritsAttribute : Attribute
    {
        public string InheritedClass { get; set; }

        public InheritsAttribute(string inheritedClass)
        {
            InheritedClass = inheritedClass;
        }
    }


As well as the syntax for specifying entity inheritance:

    [Entity]
    public interface IFoo { }

    [Entity]
    [Inherits("Foo")]
    public interface IBar { }

Which generates:

public partial class Bar : Foo, IBar { ... }


I noticed there are some "patch" files in the github repo.  If I were to create some similar patches, do you have a preferred method of doing so, or is this the way to go? http://stackoverflow.com/questions/6658313/generate-a-git-patch-for-a-specific-commit

Thanks!

Mark

Jen Williams

unread,
Oct 24, 2013, 3:58:09 AM10/24/13
to brightsta...@googlegroups.com
Hi Mark

BrightstarDB supports entity inheritance (introduced in 1.1 http://brightstardb.com/documentation/Whats_New.html) I'll take a look through the docs, but I just ran some quick code and if you define your entities similar to this:

[Entity]
public interface IBaseThing {
    string Id {get;}
    string SomeProperty {get; set; }
}

[Entity]
public interface IThing : IBaseThing {
    string Id {get;}
    string AnotherProperty {get;set;}
}

And then "run custom tool" on the .tt file, it should build your classes as you want. Unless I've misunderstood your question (let me know if so!)
The main thing to note is that both the base entity and the inherited entity require their own Id 


Hope this helps

Jen

Jen Williams

unread,
Oct 24, 2013, 4:01:10 AM10/24/13
to brightsta...@googlegroups.com
Actually the inherited entity *doesn't* appear to require the Id field for the .tt file to run successfully
Reply all
Reply to author
Forward
0 new messages