Hi guys,
Apologies if this is trivial. Now onto the post.
I am developing on the web with session per request configured. I have
two classes, Product and ProductDefinition. You can imagine Product as
an 'instance' of ProductDefinition. Product is linked to
ProductDefinition via ProductDefinitionId.
[ActiveRecord(Table = "Product")]
public class ProductBE
{
[PrimaryKey(PrimaryKeyType.Assigned)]
public Guid Id { get; set; }
[Property]
public Guid ProductDefinitionId { get; set; }
[BelongsTo("ProductDefinitionId", Insert = false, Update =
false, Lazy = FetchWhen.Immediate)]
public ProductDefinitionBE ProductDefinition { get; set; }
}
[ActiveRecord(Table = "ProductDefinition")]
public class ProductDefinitionBE
{
[PrimaryKey(PrimaryKeyType.Assigned)]
public Guid Id { get; set; }
[Property]
public string Name { get; set; }
}
As you can see, ProductDefinition holds the 'Name' column, which would
be of interest to Product. What I'm trying to do is something like
below:
[ActiveRecord(Table = "Product")]
public class ProductBE
{
[PrimaryKey(PrimaryKeyType.Assigned)]
public Guid Id { get; set; }
[Property]
public Guid ProductDefinitionId { get; set; }
[BelongsTo("ProductDefinitionId", Insert = false, Update =
false, Lazy = FetchWhen.Immediate)]
public ProductDefinitionBE ProductDefinition { get; set; }
public property Name
{
get
{
return this.ProductDefinition.Name;
}
}
}
Basically, I'm trying to make available the 'Name' column from
ProductDefinition into Product class. I am very sure there's a more
proper 'AR' way to do this. I hope someone can enlighten me as well if
that's the case. But as of now, let's proceed with what I have above.
Say now I create a new Product ( e.g
ActiveRecordBase<Product>.Create(newProduct) ). The UI will then
immediately display the newly created Product plus existing ones by
calling ActiveRecordBase<Product>.FindAll().
When FindAll is called, I believe AR flushes as I saw in the SQL
profiler the following sequence of statements
- INSERT... - due to ActiveRecordBase<Product>.Create(newProduct)
- SELECT... - due to ActiveRecordBase<Product>.FindAll()
Now, what is interesting is that the BelongsTo in Product for
ProductDefinitionBE is null, only for the newly inserted Product. The
products that exist prior to the insert are not affected.
Note also that subsequent FindAll will return instantiated BelongsTo
for the newly inserted Product.
Why does the BelongsTo for a new entity fail to be instantiated by AR?
--
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.