Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting 'column' properties
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01619178
Message ID:
01619182
Views:
48
This message has been marked as a message which has helped to the initial question of the thread.
There are a number of ways to do this.

Use a tool like Automapper, which will let you map properties of an object to another. It can create new objects or update existing objects.

For simpler things I use some helper functions like this CopyObjectData() (part of the westwind.utilities NuGet package):

https://github.com/RickStrahl/WestwindToolkit/blob/master/Westwind.Utilities/Utilities/DataUtils.cs#L241

which uses Reflection to generically copy properties from one object to another.

Note this does shallow copies meaning it just copies top level properties/values. You can exclude properties (to allow for overwriting values that you don't want updated like child objects perhaps or values that don't come in from the source object). This works fairly well for most entity objects.

Automapper is the more sophisticated solution but it requires more setup and configuration.


+++ Rick ---

>Hi everybody,
>
>I have a model class which is modeled after a view using Reverse POCO Generator. I am returning that view back. My question is - how can I get back to the properties of each column (e.g. for example, public String Salespoint {get;set;} - I need to get 'Salespoint' back)?
>
>In other words, I started this code
>
>
> foreach (var col in searchViewModel.Result.List) // List is IEnumerable of SalesPointsLicensesList class
>            {
>                
>            }
>
>I need to know the name of the column (class property) and its value. How can I get the name of the property here?
>
>Thanks in advance.
>
>UPDATE. Looks like I would need to use reflection and PropertyInfo class.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform