Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to Store Table Values In C# properties using Linq. Using GetAll() method in three tier architecture.Without using Iqueriable method.
Properties are just "Get and Set" methods nothing more.

"I want to store my table data in "get& set" properties using Linq, and Entity Framework,
and without using "Iqueriable" method.
Posted
Updated 13-Oct-15 10:32am
v2
Comments
OriginalGriff 11-Oct-15 7:19am    
What have you tried?
Where are you stuck?
What help do you need?
[no name] 13-Oct-15 16:34pm    
I use List and get whole data from table.
I stuck to store that values in "get and set" properties
I need to store that data first in my properties and then manipulate to frontend.

1 solution

First, are you aware you can use Linq on DataTable.Rows or DataTable.AsEnumerable() ?

I interpret your question as indicating you don't fully understand what Properties are in .NET. They are a strongly-typed distinct entity which encapsulates a Key-Value Pair of a Name/Value, and supports two specific internal methods: 'set, and 'get.

While it is tempting to see all the Properties in a given Class as a "Property-Bag;" that's also a waste of time because you can't do anything with the set of Class Properties as an "entity" ... There's nothing there for you to run a Linq query on !

However ... yes, you could use reflection at run-time to examine, even set the values of, the Properties in a Class instance: in doing so you will consume resources (memory/computation) that could affect your application's performance. Whether or not you could use Linq there ... I am not sure.

If you want a Property-Bag, there are some choices:

1. if you can "afford," or, are willing to deal with, late-binding: you can use the Expando Object in System.Dynamic; for example:

// required: using System.Dynamic;
public ExpandoObject MyPropertyBagExpando = new ExpandoObject();

or, you could use a Dictionary<string, dynamic>:

public Dictionary<string,dynamic> MyPropertyBagDictionary = new Dictionary<string,dynamic>();

2. if all of your properties are of the same Type, you could use one strongly typed Dictionary, or, use multiple strongly typed Dictionaries for each different Type.

Whether you use an Expando, or Dictionary, you can certainly use Linq with those; however, keep in mind that you do not normally use Linq to execute code with "side-efects," like assignment operations.

To "map" some kind of DataTable's contents to a Property-Bag calls for some kind of "transformation," the kind of thing you can with XML using an XSLT. If you really need two-way binding between some DataTable contents and some .NET collection data-structure ... well, some people might use serialization/de-serialization (since there's often a need to serialize/de-serialize).
 
Share this answer
 
v3
Comments
Maciej Los 11-Oct-15 14:21pm    
5ed!

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