locked
how to list entity field names? RRS feed

  • Question

  • I am unable to list the field names of the entity, I can get entity from (IEntitySet)this.DataWorkspace.ApplicationData.Details.Properties["myentity"].Value

    I tried to follow same logic with the details of the entity but there seems to be no Properties method.

    thanks in advance.

    Tuesday, January 8, 2013 2:02 PM

All replies

  • foreach (EntityName n in EntityNames)    
    {    
         Microsoft.LightSwitch.Model.IEntityType entityType =    
              this.Application.Details.GetModel()    
                   .GlobalItems    
                   .OfType<Microsoft.LightSwitch.Model.IEntityType>()    
                   .Single(e => e.Name.Equals(n.Name, StringComparison.Ordinal));

         foreach (string s in entityType.Properties.Select(p => p.Name)   
                   .Except(PropertyNames    
                   .Where(pn => pn.EntityName.Equals(n))    
                   .Select(pn => pn.Name)    
                   .Union(entityType.NavigationProperties.Select(np => np.Name))))     //not nav props
         {    
              PropertyName _propertyName = new PropertyName();    
              _propertyName.Name = s;    
              _propertyName.EntityName = n;    
         }    
    }

    This was cut and pasted from:

    Microsoft LightSwitch Entity Names and Properties Self Populating Tables

    Mike


    • Proposed as answer by Angie Xu Thursday, January 24, 2013 7:58 AM
    • Edited by Yann DuranModerator Sunday, March 17, 2013 8:30 AM Fixed link text
    Tuesday, January 8, 2013 7:46 PM