25 October, 2011
0 Comments
1 category
If you want to list all entity names / table names from your Entity Framework model (*.edmx) in Silverlight 4, use a RIA Invoke operation:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Metadata.Edm; using System.ServiceModel.DomainServices.Server; namespace Research.Web { public partial class ResearchDomainService { /// <summary> /// Get the entity names from the entity framework model on which this DomainService is generated. /// </summary> /// <returns> /// A list of entity / table names /// </returns> [Invoke] public List<string> GetEntityTypeNames() { EntityContainer container = ObjectContext.MetadataWorkspace.GetEntityContainer(ObjectContext.DefaultContainerName, DataSpace.CSpace); List<string> result = (from meta in container.BaseEntitySets where meta.BuiltInTypeKind == BuiltInTypeKind.EntitySet select meta.ElementType.ToString()).ToList<string>(); return result; } } }
If the database contains the following tables:
The list will contain the strings:
ResearchModel.Customer
ResearchModel.Person
ResearchModel.Product
ResearchModel.ProductTag
ResearchModel.Tag
Category: Uncategorized
I actually had been exploring for creative concepts
for my personal weblog and came across your post, “How to list all
entity names / table names from your Entity Framework
model in Silverlight 4 and RIA services”, will you care in
cases where I actually work with many of your own points?
With thanks ,Greg