0 Comments

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:

 

image

 

The list will contain the strings:

ResearchModel.Customer

ResearchModel.Person

ResearchModel.Product

ResearchModel.ProductTag

ResearchModel.Tag

One Reply to “How to list all entity names / table names from your Entity Framework model in Silverlight 4 and RIA services”

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts