Click here to Skip to main content
15,070,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As the question asks, is there a way to tell whether a given object is a complex type or an entity?

This is my current code where ent is the object context:

C#
var objectResult = (from meta in ent.MetadataWorkspace.GetItems(DataSpace.CSpace)
                                        .Select(m => m)
                                   from p in (meta as EntityType).Properties
                                       .Where(p => p.DeclaringType.Name == entity.GetType().Name)
                                   select p);

int count = objectResult.Count();


...the call to objectResult.Count() results in an Object reference not set to an instance of an object exception if the object is not an Entity type. I can trap this if necessary but am hoping there's another way around it?
Posted
Comments
Abinash_Sahoo 11-Apr-14 12:24pm
   
try to check if (meta is EntityType) in the condition; sorry forgot the syntax now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900