I'm trying to achieve scalability and to centralize managment of the
original images, I want to store them in the DB to keep a constraint aswell.
It could be, however, solved using dedicated mediaservers, using
networked mapped drives for that matter. Space seldom is an issue
nowadays, although if I cannot get this lazy loading to work I'm stuck
anyway.
My syntax was somehow incorrect, you cannot have Lazy on a BelongsTo, it
was only the class-attribute that had Lazy.
It has the effect that it actually selects imageData in a separate
query, but it doesn't become proxied and therefor is always loaded when
lookup up a Product.
I had another thought, about having Image and extend that with
ImageWithData, where Image would never be aware of the binary-data. Both
would map against the same table, and when instantiated as Image it
would never be aware of any binarydata, hence, not load it. Not sure if
this approach is doable though, the plan was to just typecast it to
ImageWithData and refresh it when I needed the binary data.
PKetelle wrote:
> Would it not be easier to have the Images saved on the local disc and
> just keep the paths in the database to reduce the database size from
> going crazy ?
>
> However would the Image Class not be
>
> [ActiveRecord]
> public class Image
> {
> [PrimaryKey( PrimaryKeyType.Native)]
> public override int Id { get; set; }
> private ImageData data;
> [BelongsTo("ImageData", Lazy = true)]
> public MyImageData Data
> {
> get { return data; }
> set { data = value; }
> }
> }
>
> as this is how I have done Lazy loading before.
>
> I do sometimes find that if you have not accessed the ImageData Value
> before you render the view that you can't access the ImageData at all.
>
>
>
> On Oct 17, 10:44 am, Jimmy Shimizu <[EMAIL PROTECTED]> wrote:
>
>> I'm trying to enable lazy-loading of a Property in one of my entities,
>> but I keep running into trouble.
>>
>> Explanation of problem:
>>
>> I have an Image-class that contains info about an image, filename, size,
>> type etc, including binary data of the object. Since the binary data can
>> become huge, I need to be able to load the image without that data
>> unless explicitly addressed.
>>
>> Since you cannot specify Lazy on a property, I needed another solution
>> to the problem. First idea was to use a Nested class, but that however
>> doesn't support Lazy either.
>>
>> Second idea was to use a OneToOne relation, but that doesn't support
>> Lazy either.
>>
>> Third idea, found
>> here:http://gnschenker.blogspot.com/2007/06/one-to-one-mapping-and-lazy-lo...,
>> when using OneToOne with a BelongsTo gives the possibility to add Lazy
>> to the BelongsTo, however I don't get this to work.
>>
>> I can't seem to get my head around this Lazy-loading. This is my setup:
>>
>> [ActiveRecord( "`product`", "products")]
>> public class Product
>> {
>> [HasAndBelongsToMany( typeof( Image ), Lazy = true, Inverse = false]
>> public virtual ISet<Image> Images {}
>>
>> }
>>
>> [ActiveRecord( Lazy = true )]
>> public class Image
>> {
>> [PrimaryKey( PrimaryKeyType.Native)]
>> public override int Id { get; set; }
>>
>> private ImageData data;
>>
>> [BelongsTo(Lazy = true)]
>> public virtual ImageData Data
>> {
>> get { return this.data; }
>> set
>> {
>> value.Image = this;
>> this.data = value;
>> }
>> }
>>
>> }
>>
>> [ActiveRecord( Lazy = true )]
>> public class ImageData
>> {
>> [PrimaryKey( PrimaryKeyType.Foreign )]
>> public virtual int Id { get; set; }
>>
>> [OneToOne( Constrained = true )]
>> public virtual Image Image { get; set; }
>>
>> }
>>
>> The code is heavily simplified, but this setup gives me:
>> NHibernate.Id.IdentifierGenerationException: null id generated for:
>> ImageData
>>
>> If I try to use OneToOne on both Entities (Image and ImageData) it seem
>> to work, but Lazy doesn't work.
>>
>> Another weird issue is that when having the Images-collection on Product
>> set to Lazy, it still doesn't generate proxy-objects of Images, I
>> thought that was the primary goal with Lazy? Where can I find some
>> useful guides regarding Lazy-loading that can explain it in detail?
>>
>> Even Lazy on my ImageData-class doesn't seem to make any difference, I
>> would assume that having OneToOne on everything, then Lazy on ImageData
>> would generate proxy-object, but that doesn't seem to be the case.
>>
>> // Jimmy
>>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---