I can't use LivePersistence... can I?

Posts   
 
    
dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 25-Jul-2007 14:50:25   

ASP.NET 2.0, C#, VS 2005, LLBLGenPro 2.0.0.0 (final) Released June 15th, 2007. Using SelfServicing, 2 class.

I have a page that is to manage a master-detail relationship. I have a gridview that displays a list of Installation Locations (Caption, Active, Added By, Added On). When I row in the Gridview is selected, I utilize a FormView control to display the InstallationPhoto Entities for the selected Installation. InstallationEntity has a collection of InstallationPhotoEntities, InstallationPhotoEntity has Active(bool), AddedBy(GUID), AddedOn(DateTime), Thumbnail(Byte[]), Image(Byte[]).

I have 2 LLBLGenProDatasource Controls on the form, on for the InstallationEntityCollection and one for the InstallationPhotoEntityCollection. I set everything up using LivePersistence=true and it works flawlessly, displaying all of the data, even the thumbnil images.

However, now I need to handle adding new InstallationEntities as well as new InstallationPhotoEntities. I assume I could get the InstallationEntities added by utilizing a footer template in the gridview and InsertParameters to set the UID(GUID), AddedByUserUID(GUID) and AddedDate(DateTime).

Where I am stuck is on the photo. I utilize a file upload control and catch the Inserting Event of the form view. There, I resize the image, create the thumbnail and convert both the image and the thumbnail to a byte array. I don't think I can use insert parameters to get a byte array into the db?

I really need to switch my approach don't I? Any advice?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2007 15:44:05   

Where I am stuck is on the photo. I utilize a file upload control and catch the Inserting Event of the form view. There, I resize the image, create the thumbnail and convert both the image and the thumbnail to a byte array. I don't think I can use insert parameters to get a byte array into the db?

I really need to switch my approach don't I? Any advice?

Handle the Data Source EntityInserting event, as follows:

        protected void InstallationPhoto_DS_EntityInserting(object sender, CancelableDataSourceActionEventArgs e)
        {
            FileUpload fileUpload = (FileUpload)InstallationPhotoFormView.FindControl("FileUpload1");

            if (fileUpload.PostedFile != null && !string.IsNullOrEmpty(fileUpload.PostedFile.FileName) && fileUpload.PostedFile.InputStream != null)
            {
                ((InstallationPhotoEntity)e.InvolvedEntity).Picture = fileUpload.FileBytes;
            }       
        }
dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 25-Jul-2007 15:46:41   

I ussume that I can use the same technique to set -UID(GUID) - Primary Key -InstallationUID(GUID) - Foreign Key -AddedByUserUID(GUID) - Foreign Key -AddedDate(DateTime) ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2007 15:57:01   

Yes you can, and you can use InsertParameters too.

dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 25-Jul-2007 16:00:21   

I haven't yet found enough examples using insertparameters to get comfortable using them. I know that it must be easy to use an insert parameter to set the ForeignKey InstallationUID = to the UID of the InstallationEntity currently selected in the GridView, I just haven't been able to implement it. Maybe the examples are there and I am just being lazy wink

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2007 16:17:57   

In the same event handler (EntityInserting), you can do the following:

            InstallationPhoto_DS.InsertParameters.Add(InstallationPhotoFields.AddedByUserUID.Name, SomeValue_From_Somewhere);

And you can add InsertParameters in the ASPX code the same way you use SelectParameters. Example:

        <llblgenpro:LLBLGenProDataSource ID="OrderDetailsDS" runat="server" DataContainerType="EntityCollection"
            EntityCollectionTypeName="SD.LLBLGen.Pro.Examples.CollectionClasses.OrderDetailCollection, SD.LLBLGen.Pro.Examples"
            SortingMode="ClientSide">
            <SelectParameters>
                <asp:ControlParameter ControlID="OrdersFormView" Name="OrderId" PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
            <InsertParameters>
                <asp:ControlParameter ControlID="OrdersFormView" Name="OrderId" PropertyName="SelectedValue"
                    Type="String" />
            </InsertParameters>
        </llblgenpro:LLBLGenProDataSource>
dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 25-Jul-2007 19:10:44   

What namespace is CancelableDataSourceActionEventArgs in?

Further, I don't even see where the LLBLGenProDatasource raises an EntityInserting event

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 09:07:17   

Oh I forgot to metnion that these are from v.2.5 (currently beta, the final release is very soon)

dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 26-Jul-2007 14:02:44   

Can I install 2.5 in parrallel with 2.0?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 16:30:29   

Yes, sure.

dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 26-Jul-2007 16:35:16   

Yeah, got it going now.

Had to use DataSourceActionEventArgs instead of CancelableDataSourceActionEventArgs as the second parameter for the event handler.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 16:44:54   

CancelableDataSourceActionEventArgs is the Cancelable variant of the DataSourceActionEventArgs, it is found under SD.LLBLGen.Pro.ORMSupportClasses namespace.

dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 26-Jul-2007 16:46:26   

gotcha