JamesJ

Hi,

Now I am working on DAL class design. And I am using Custom Entity object to map the data from database. For example, I have a class name Product, it has some properties: ProductName, ProductId, Weight, Height,Length ,etc..

And I have some Stored Procedures for example: GetProudctInfoById which only returns ProductId and ProductName.

the other Stored Procedure would be GetProductDimensionById which will return Weight, height and leght, but It won't return ProductName and other Info.

All those two stored procedure will map to Product Entity Class. But the Product Enitity has more properties than the number of columns those two Stored Procedures return. What I want is If Call GetProductDimensionById, the Proudct Class only has Weight, Height,Length properties and hide all other properties.

I tried to use attributes to do it, it seems not to work for me. Or dynamically create a class (I won't do that)

Any thoughts Please help me out. If you can provider some code snippets, it would be grateful.

Thank you.



Re: Visual C# General How to dynamically hide properties of class

Chris Eargle

Please post a code example of where the failure is occurring. In typical ORM scenarios, you check that the row has the column you're trying to map. If it doesn't, the entity maintains its default value for that column.






Re: Visual C# General How to dynamically hide properties of class

Chunsheng Tang - MSFT

Hi,

Hiding some properties fo an entity does not seem to make sense. Technically there are some options:

1. Create a base class with the common and basic properties, and then derive this base class for extended properties.

2. Create an interface that has the properties you want from the product, and use the interface explicitly, then the other properties outside of the interface are hidden.

Best Regards

Chunsheng Tang