Add Method to EntityFieldFactory

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 29-May-2006 18:14:04   

Could this be added to the standard field factory template?

public static IEntityField2 Create(string entityName, string entityFieldName)
        {
            IFieldInfoProvider provider = FieldInfoProviderSingleton.GetInstance();
            IEntityField2 fieldToReturn = null;
            fieldToReturn = new EntityField2(provider.GetFieldInfo(entityName, entityFieldName));
            return fieldToReturn;
        }

Or is there someplace else this fuctionality is exposed?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 29-May-2006 18:43:25   

You only know the name? as you can use the EntityFieldFactory or EntityFieldsFactory objects with enums to get the right field object?

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 29-May-2006 18:55:57   

I'm building this at run time, based on things like the name of the entityfield displayed in the column of a grid. This info is pretty easily available. The Entity.FieldIndex enum value isn't since it could be any entity and there is not one big enum that contains all fields (that I know of).

Or am I missing a better way to do this kind of thing?


    private void gridInvoices_FilterChange(object sender, EventArgs e) {
      C1TrueDBGrid grid = sender as C1TrueDBGrid;
      if(grid != null) {
        // build our filter expression
        PredicateExpression filter = new PredicateExpression();

        foreach(C1DataColumn dc in grid.Columns) {
          if(dc.FilterText.Length > 0) {
            //TODO: replace hardcoded entity name with variable!
            IEntityField2 field = EntityFieldFactory.Create("InvoiceEntity", dc.Caption);
            IPredicate pred;
            switch(field.DataType.Name) {
              case "String":
                pred = new FieldLikePredicate(field, null, dc.FilterText);
                break;
              case "Int32":
                pred = new FieldCompareValuePredicate(field, null, ComparisonOperator.Equal, dc.FilterText);
                break;
              case "DateTime":
                DateTime work;
                if (DateTime.TryParse(dc.FilterText, out work)) {
                  pred = new FieldCompareValuePredicate(field, null, ComparisonOperator.Equal, work);
                }
                break;
              default:
                Debug.Assert(false,"Deal with data type");
                pred = new FieldCompareValuePredicate(field, null, ComparisonOperator.Equal, dc.FilterText);
                break;
            }
            if( pred != null) {
              filter.AddWithAnd(pred);
            }
          }
        }
        // filter the data
          EntityView2<InvoiceEntity> vw = grid.DataSource as EntityView2<InvoiceEntity>;
          if (filter.Count > 0)
          {
            try
            {
            vw.Filter = filter;
          }
          catch(ArgumentOutOfRangeException except) {
            Debug.Write(except.Message);
          }
        } else {
          vw.Filter = null;
        }
      }
    }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 29-May-2006 19:26:34   

It's indeed a valid addition, your suggestion. I thought about using System.Enum but thatwon't compile as you can't cast to the right enum because you dont know that until at runtime.

I'll add the method.

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 29-May-2006 19:58:22   

Thanks, I'm loving the EntityView so far.