Can someone provide a sample of creating a custom key generator, I am using 4.4.

I have tried adding the


This throws an exception during perform: "[KeyGenerator] attribute on type 'VirtualMedia' requires Name to be set"

So I tried this:

[KeyGenerator(typeof(MyGenerator), Name="foo")]

This throws Service with name "foo" of type 'MyGenerator' is not available.

The sample in the documentation is apparently outdated as classes like KeyProviderInfo are not even in the framework.

asked Apr 24 '12 at 15:37

MikeBenson's gravatar image


One Answer:

I figure this out, the documentation really needs updated:

Here is the sample demonstrating how to do it:

[KeyGenerator(typeof(MyGenerator), Name = "foo")]
public abstract class MyBaseClass : Xtensive.Orm.Entity

[Service(typeof(MyGenerator), Name = "foo")]
public class MyGenerator : KeyGenerator<Guid>
    public override Xtensive.Tuples.Tuple TryGenerateKey(bool temporaryKey)
        return Xtensive.Tuples.Tuple.Create(Guid.NewGuid());

You will also need to register the "MyGenerator" type in the domain configuration.

answered Apr 24 '12 at 16:19

MikeBenson's gravatar image


Hello Mike, sorry for inconvenience. You are right this is the correct way to create custom key generator. It allows you to create completely customized key generator. The other option is to use standard DO.Net approach with XXX-Generator tables.

By default one table is used for each key type (int or long). You can however declare your own generator table named for example foo-Generator by creating class that inherits CachingKeyGenerator<t> and attributing it the same way.

(Apr 25 '12 at 04:39) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

Ok, documentation still not up-to-date because I just ran into the same thing unnecessarily... :/

(Aug 01 '12 at 08:30) Jos Jos's gravatar image

Yes, sorry for that. We are working on this.

(Aug 03 '12 at 07:02) Dmitri Maximov Dmitri%20Maximov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Apr 24 '12 at 15:37

Seen: 4,637 times

Last updated: Aug 03 '12 at 07:02

powered by OSQA