Sure thing :)

I have removed a few things but the essential things should be there


public abstract class BaseEntity<T> : ActiveRecordValidationBase<T>
where T : class
{
    private readonly DateTime created;
    private DateTime modified;

    public BaseEntity()
    {
        created = DateTime.Now;
        modified = DateTime.Now;
    }

    [Property("Created", Access = PropertyAccess.NosetterLowercase,
NotNull = true)]
    public DateTime? Created
    {
        get { return created; }
    }

    [Property("Modified", Access = PropertyAccess.NosetterLowercase,
NotNull = true)]
    public DateTime Modified
    {
        get { return modified; }
    }

    public override void Update()
    {
        modified = DateTime.Now;
        base.Update();
    }

    public override void UpdateAndFlush()
    {
        modified = DateTime.Now;
        base.UpdateAndFlush();
    }

    public override void Save()
    {
        modified = DateTime.Now;
        base.Save();
    }

    public override void  SaveAndFlush()
    {
        modified = DateTime.Now;
        base.SaveAndFlush();
    }

    protected override void OnSave()
    {
        modified = DateTime.Now;
        base.OnSave();
    }

    protected override void OnUpdate()
    {
        modified = DateTime.Now;
        base.OnUpdate();
    }
}

public class Blog : BaseEntity<Blog>
{
    [PrimaryKey(PrimaryKeyType.GuidComb, "Id", Access =
PropertyAccess.NosetterLowercase)]
    public Guid Id
    {
        get { return id; }
    }

    [Property("Name", NotNull = true, Length = 255), ValidateNonEmpty
("Name is a required field")]
    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    [HasMany(typeof(Post),
        Table = "Posts",
        ColumnKey = "BlogId",
        Access = PropertyAccess.NosetterCamelcase,
        RelationType = RelationType.Bag,
        Cascade = ManyRelationCascadeEnum.AllDeleteOrphan,
        Inverse = true
        )]
    private IList<ProductVariantValue> Posts
    {
        get { return posts; }
    }

    public List<Post> PostList
    {
        get { return new List<Post>(Posts).AsReadOnly(); }
    }

        public void AddPost(Post post)
        {
                posts.Add(post);
        }

        public void RemovePost(Post post)
        {
                posts.Remove(post);
        }
}

public class Post : BaseEntity<Post>
{
    public Post(string value)
    {
        this.text = value;
    }

    [PrimaryKey(PrimaryKeyType.GuidComb, "Id", Access =
PropertyAccess.NosetterLowercase)]
    public Guid Id
    {
        get { return id; }
    }

    [Property("BlogId", NotNull = true)]
    public Guid BlogId
    {
        get { return blogId; }
        set { blogId = value; }
    }

    [Property("Text", NotNull = true), ValidateNonEmpty("Text is a
required field")]
    public string Text
    {
        get { return text; }
        set { text = value; }
    }
}





On Jan 9, 3:53 pm, "Markus Zywitza" <[email protected]> wrote:
> Can you post the Post type please?
>
> 2009/1/9 Mark Jensen <[email protected]>:
>
>
>
> > Thanks, I read that... but I dont understand the Paramter in the
> > CreateSchema()
>
> > anyway...it is not the ID on Post that is the problem.. it is the
> > BlogID on Post that is empty after I persist Blog with Blog.Save().
>
> > On Jan 9, 3:00 pm, "Markus Zywitza" <[email protected]> wrote:
> >> schema 
> >> generation:http://www.castleproject.org/activerecord/documentation/trunk/usersgu...
>
> >> When you create a new Post, it's ID is Guid.Empty. That's just fine,
> >> as this is the unsaved value. When the post is saved and flushed, it
> >> is assigned an Guid generated by NH.
>
> >> -Markus
>
> >> 2009/1/9 Mark Jensen <[email protected]>:
>
> >> > I have switched over to Guids (GuidComb) instead....
>
> >> > Now the foreignkey in Post is just guid.empty :/ when I create a new
> >> > Blog and add a Post to it.
>
> >> > On Jan 9, 1:19 pm, "Markus Zywitza" <[email protected]> wrote:
> >> >> Here is my setup/teardown:
>
> >> >>         [SetUp]
> >> >>         public void Setup()
> >> >>         {
> >> >>             ActiveRecordStarter.Initialize(
> >> >>                 ActiveRecordSectionHandler.Instance,
> >> >>                 typeof(SubjectUnderTest), 
> >> >> typeof(OtherNeededTypesForTest));
> >> >>             ActiveRecordStarter.CreateSchema(typeof(ActiveRecordBase));
> >> >>         }
>
> >> >>         [TearDown]
> >> >>         public void Teardown()
> >> >>         {
> >> >>             ActiveRecordStarter.DropSchema(typeof(ActiveRecordBase));
> >> >>             ActiveRecordStarter.ResetInitializationFlag();
> >> >>         }
>
> >> >> The typeof(ActiveRecordBase) in Create/Drop is necessary to keep AR
> >> >> from modifying the schema on other databases than the primary
> >> >> testdatabase.
>
> >> >> -Markus
>
> >> >> 2009/1/9 Mark Jensen <[email protected]>:
>
> >> >> > anyway, if i leave out the update method I get the following exception
>
> >> >> > "Dialect does not support identity key generation"
>
> >> >> > On Jan 8, 8:50 pm, "Markus Zywitza" <[email protected]> wrote:
> >> >> >> ActiveRecordStarter.CreateSchema();
> >> >> >> ActiveRecordStarter.DropSchema();
> >> >> >> ActiveRecordStarter.UpdateSchema();
>
> >> >> >> 2009/1/8 Mark Jensen <[email protected]>:
>
> >> >> >> > recreate? how
>
> >> >> >> > Atm I running the thing in a unittest where I do the following
>
> >> >> >> >  XmlConfigurationSource source = new XmlConfigurationSource("../../
> >> >> >> > AppConfig.xml");
> >> >> >> >  Assembly asm = Assembly.Load("myDomain");
> >> >> >> >  ActiveRecordStarter.Initialize(asm, source);
>
> >> >> >> > On Jan 8, 4:10 pm, "Markus Zywitza" <[email protected]> 
> >> >> >> > wrote:
> >> >> >> >> You have to recreate the schema. It creates a table to store the 
> >> >> >> >> next hi to use.
>
> >> >> >> >> 2009/1/8 Mark Jensen <[email protected]>:
>
> >> >> >> >> > When I switch my primarykeys on Blog and Post to HiLo I get the
> >> >> >> >> > following error
>
> >> >> >> >> > System.Data.SqlClient.SqlException: Invalid object name
> >> >> >> >> > 'hibernate_unique_key'.
>
> >> >> >> >> > On Jan 8, 3:51 pm, "Markus Zywitza" <[email protected]> 
> >> >> >> >> > wrote:
> >> >> >> >> >> GuidComb is nearly as fast as Identity. With AR/NH its even 
> >> >> >> >> >> faster
> >> >> >> >> >> because Identity requires NH to hit the DB when you call Save()
> >> >> >> >> >> instead of flushing all at once. This also has side effects to
> >> >> >> >> >> cascading, what is why I asked.
>
> >> >> >> >> >> If you need numerical IDs, use HiLo instead. You can quick try 
> >> >> >> >> >> this
> >> >> >> >> >> without changing your classes to see whether cascading works as
> >> >> >> >> >> expected without Identity PKs.
>
> >> >> >> >> >> -Markus
>
> >> >> >> >> >> 2009/1/8 Mark Jensen <[email protected]>:
>
> >> >> >> >> >> > Atm, yes....
>
> >> >> >> >> >> > I haven't really dicided if I shoud go with Identity og 
> >> >> >> >> >> > Guids.... I
> >> >> >> >> >> > have choosen Identity so fare, because i believe it to be 
> >> >> >> >> >> > faster..
>
> >> >> >> >> >> > On Jan 8, 3:46 pm, "Markus Zywitza" 
> >> >> >> >> >> > <[email protected]> wrote:
> >> >> >> >> >> >> Do you use MSSQL Identity for your PKs?
>
> >> >> >> >> >> >> -Markus
>
> >> >> >> >> >> >> 2009/1/8 Mark Jensen <[email protected]>:
>
> >> >> >> >> >> >> > BTW. when I Add a new Post the BlogID is zero when I 
> >> >> >> >> >> >> > persist this way
> >> >> >> >> >> >> > Blog.Save();
>
> >> >> >> >> >> >> > On Jan 8, 3:18 pm, "Markus Zywitza" 
> >> >> >> >> >> >> > <[email protected]> wrote:
> >> >> >> >> >> >> >> 2009/1/8 Mark Jensen <[email protected]>:
>
> >> >> >> >> >> >> >> >        [HasMany(typeof(Post),
> >> >> >> >> >> >> >> >            Table = "Posts",
> >> >> >> >> >> >> >> >            ColumnKey = "BlogId",
> >> >> >> >> >> >> >> >            Access = PropertyAccess.NosetterCamelcase,
> >> >> >> >> >> >> >> >            RelationType = RelationType.Bag,
> >> >> >> >> >> >> >> Inverse = true,
> >> >> >> >> >> >> >> >            Cascade = ManyRelationCascadeEnum.SaveUpdate
> >> >> >> >> >> >> >> >            )]
> >> >> >> >> >> >> >> >        private IList<Post> PostList
> >> >> >> >> >> >> >> >        {
> >> >> >> >> >> >> >> >            get { return postlist; }
> >> >> >> >> >> >> >> >        }
>
> >> >> >> >> >> >> >> -Markus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to