Problems with LLBLGenProDataSource2 under SharePoint

Posts   
 
    
Posts: 1
Joined: 25-Nov-2009
# Posted on: 25-Nov-2009 23:21:34   

Dear support,

Can you please help me with problem, which relates to fields validation?

Here is the markup of the ascx control, which connects to entity framework using LLBLGenProDataSource2 and presents data using RadGrid:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl.ascx.cs" Inherits="RadControls.WebUserControl" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2009.3.1103.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
    Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.6.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27" namespace="SD.LLBLGen.Pro.ORMSupportClasses" tagprefix="llblgenpro" %>

        <telerik:RadGrid ID="rgMarkers" runat="server" AllowSorting="True" DataSourceID="LLBLGenProDataSource21"
            GridLines="None" ShowStatusBar="True" AutoGenerateColumns="False" AllowAutomaticUpdates="true"
            onupdatecommand="rgMarkers_UpdateCommand">
            <MasterTableView RetrieveAllDataFields="false" EditMode="InPlace" DataKeyNames="MarkerId" >
                <Columns>
                    <telerik:GridEditCommandColumn UniqueName="EditButton" ButtonType="ImageButton">
                        <HeaderStyle Width="20px" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn UniqueName="MarkerName" DataField="MarkerName" HeaderText="Marker Name" />
                    <telerik:GridBoundColumn UniqueName="MarkerType" DataField="MarkerType" HeaderText="Marker Type" />
                    <telerik:GridBoundColumn UniqueName="NormalizationTypeName" DataField="NormalizationTypeName" HeaderText="Normalization Type Name" />
                    <telerik:GridBoundColumn UniqueName="EffectiveDate" DataField="EffectiveDate" HeaderText="Effective Date" />
                    <telerik:GridBoundColumn UniqueName="CreatedDate" DataField="CreatedDate" HeaderText="Created Date" />
                    <telerik:GridBoundColumn UniqueName="CreatedBy" DataField="CreatedBy" HeaderText="Created By" />
                </Columns>

            </MasterTableView>
        </telerik:RadGrid>
        
<asp:CustomValidator ID="CustomValidator1" runat="server" Display="None"></asp:CustomValidator>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />

    <llblgenpro:LLBLGenProDataSource2 ID="LLBLGenProDataSource21" runat="server" cachelocation="Session"
        DataContainerType="EntityCollection" 
        EntityFactoryTypeName="DxNi.Biochem.Data.FactoryClasses.MarkerEntityFactory, DxNi.Biochem.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=685eca69e506fb5e"
        AdapterTypeName="DxNi.Biochem.Data.DatabaseSpecific.DataAccessAdapter, DxNi.Biochem.DataDBSpecific, Version=1.0.0.0, Culture=neutral, PublicKeyToken=685eca69e506fb5e" 
        LivePersistence="False" 
        OnPerformGetDbCount="orderDS_PerformGetDbCount" 
        OnPerformSelect="orderDS_PerformSelect" OnPerformWork="orderDS_PerformWork" 
        ThrowExceptionOnIllegalFieldInput="true" EnableViewState="true">
    </llblgenpro:LLBLGenProDataSource2>

Here is the code behind:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using Telerik.Web.UI;
using System.Data;
using System.Collections;
using DxNi.Biochem.DomainLayer.BPM.ConfigurationManagers.Interfaces;
using DxNi.Biochem.DomainLayer.BPM.ConfigurationManagers.ConcreteClasses;
using DxNi.Biochem.Data.EntityClasses;
using DxNi.Biochem.Data.DatabaseSpecific;
using SD.LLBLGen.Pro.ORMSupportClasses;
using DxNi.Biochem.DomainLayer.BPM.ConfigurationManagers.ValidatorClasses;
using System.ComponentModel;


namespace RadControls
{
    public partial class WebUserControl : System.Web.UI.UserControl
    {
        int updateIndex = -1;
        Dictionary<string, string> values = null;
        private IEntityManager<MarkerEntity> m_entityManager;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.m_entityManager = ConfigurationFactory.CreateEntityManager<MarkerEntity>();
        }

        #region Events

        protected void rgMarkers_UpdateCommand(object source, GridCommandEventArgs e)
        {
            this.updateIndex = e.Item.ItemIndex;

            values = new Dictionary<string, string>();

            this.rgMarkers.Items[this.updateIndex].ExtractValues(values);
        }

        protected void orderDS_PerformGetDbCount(object sender, PerformGetDbCountEventArgs2 e)
        {
            // get the total number of orders which match the filter passed in via the
            // PerformGetDbCountEventArgs2.
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                e.DbCount = adapter.GetDbCount(e.ContainedCollection, e.Filter);
            }
        }

        protected void orderDS_PerformSelect(object sender, PerformSelectEventArgs2 e)
        {
            this.LLBLGenProDataSource21.EntityCollection = this.m_entityManager.GetEntities();
        }

        protected void orderDS_PerformWork(object sender, PerformWorkEventArgs2 e)
        {
            List<UnitOfWorkElement2> updates = e.Uow.GetEntityElementsToUpdate();

            bool hasUpdated = false;
            foreach (MarkerEntity entity in this.LLBLGenProDataSource21.EntityCollection)
            {
                if (entity.IsDirty)
                {
                    hasUpdated |= this.m_entityManager.ModifyEntity(entity);
                }
            }

            string errorMessage = string.Empty;
            if (!hasUpdated)
            {
                bool hasEntityValidationError = !string.IsNullOrEmpty(((IDataErrorInfo)updates[0].Entity).Error);
                this.ValidationSummary1.HeaderText = String.Format("Entity in line {0} had following validation errors: {1}",
                        this.updateIndex + 1,
                        ((IDataErrorInfo)updates[0].Entity).Error);
                //object obj = this.GridView1.Rows[this.updateIndex].DataItem;

                bool hasFieldsValidationError = false;
                for (int i = 0; i < updates[0].Entity.Fields.Count; i++)
                {
                    bool hasFieldValidationError = !string.IsNullOrEmpty(((IDataErrorInfo)updates[0].Entity)[updates[0].Entity.Fields[i].Name]);
                    hasFieldsValidationError |= hasFieldValidationError;

                    if (hasFieldValidationError)
                    {
                        this.CustomValidator1.ErrorMessage += String.Format("Field '{0}' had an validation error '{1}' for value '{2}'",
                            updates[0].Entity.Fields[i].Name,
                            ((IDataErrorInfo)updates[0].Entity)[updates[0].Entity.Fields[i].Name],
                            this.values[updates[0].Entity.Fields[i].Name]);
                    }
                }

                //this.CustomValidator1.IsValid = !(hasEntityValidationError || hasFieldsValidationError);
                this.CustomValidator1.IsValid = false;
            }
            else
            {
                this.LLBLGenProDataSource21.EntityCollection = this.m_entityManager.GetEntities();
            }
        }

        #endregion // Events
    }
}

This is the function for validation

MarkerName

field:


     [DependencyInjectionInfo(typeof(MarkerEntity), "Validator",
     ContextType = DependencyInjectionContextType.NewInstancePerTarget)]
     public class MarkerEntityValidator : ValidatorBase
     {
          public override bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, object value)
          {
               MarkerEntity markerDefinition = involvedEntity as MarkerEntity;

               switch (fieldIndex)
               {
                    case (int)MarkerFieldIndex.MarkerName:
                         {

                              if (!Regex.Match(value.ToString(), "^[a-zA-Z0-9]*$").Success)
                              {
                                   markerDefinition.SetEntityFieldError(MarkerFields.MarkerName.Name, "A marker's name can only contain alphanumeric characters.", false);
                                   return false;
                              }
                         }
                         break;
               }
               return true;
          }
     }

This code works fine and in updates custom validator in a proper manner.

The problems starts, when I use the same user control in SharePoint 2007 MOSS. Then the validation function is never called.

I also realized that in SharePoint the order calls of PerformSelect and PerformWork are different.

Did you face something similar before?

Regards, Michael Raizman

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Nov-2009 04:46:11   

Hi Michael,

  • I guess the validator class don't get inserted into the instance class. Is there any way you can debug that the someentity.ValidatorToUse is not null in that point?

  • What is your LLBLGen version and runtime library version? (http://llblgen.com/tinyforum/Messages.aspx?ThreadID=7722)

I also realized that in SharePoint the order calls of PerformSelect and PerformWork are different.

Are you sure? please elaborate more on this test of yours.

David Elizondo | LLBLGen Support Team