Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hell All

i am using
List<ExpandoObject>
but if we use linq that time i am not getting property

What I have tried:

<pre>  var grdfeatchobjlist = (List<ExpandoObject>)grdproductitem.ItemsSource;


var getlist = grdfeatchobjlist.Select(x => x.GetType().GetProperty("batchId") == Txtbatchcode.Text.ToString());
Posted
Updated 19-Apr-18 22:36pm
v2

1 solution

If the property name is known at compile time, cast the ExpandoObject to dyanmic, and access the property directly:
C#
var getlist = grdfeatchobjlist.Select((dynamic x) => x.batchId == Txtbatchcode.Text);

For a dynamic property name which isn't known until runtime, cast the ExpandoObject to an IDictionary<string, object>, and use the indexer:
C#
var getlist = grdfeatchobjlist.Select((IDictionary<string, object> x) => x["batchId"] == Txtbatchcode.Text);
 
Share this answer
 
Comments
Member 8735045 20-Apr-18 2:37am    
Thank's for comment Richard , i try to use this
Member 8735045 20-Apr-18 4:36am    
I want to this ,
thanks Richard.

var grdfeatchobjlist =grdproductitem.ItemsSource.OfType<expandoobject>().Select((dynamic x) => x);

long StockId = Convert.ToInt64(stockId.Text);


(from u in grdfeatchobjlist where u.stockId == StockId select u).ToList()
.ForEach(u => {
u.newExpiryDate = Convert.ToDateTime(Txtexpierydate.Text).ToString("yyyy-MM-dd");
u.newSaleRate = Txtnewretailmerp.Text;
u.newMrp = Txtnewretailmerp.Text;
u.purchaseRate = Txtnewpurchasemrp.Text;
u.Status = "Yes";
u.createdby = LoginUserDetails.loginUserName.ToString();

});
Member 8735045 20-Apr-18 5:18am    
if
var datalist = JsonConvert.DeserializeObject<List<expandoobject>>(jsonResult, converter);
object is property value is null that time ExpandoObject can not be DeserializeObject

what we are missing
Richard Deeming 20-Apr-18 7:06am    
Assuming converter is an instance of the ExpandoObjectConverter class, that code should work. Make sure the property exists in your JSON data, and that you've matched the case of the property correctly.

(Eg: stockId is not the same as StockId or stockID.)
Member 8735045 20-Apr-18 7:52am    
This is my json
{
"orgId": 1,
"oprId": 1,
"productCode": 143654,
"stockId": 122104,
"batchId": 122104,
"rateId": 122104,
"shortName": "SME",
"batchNo": "150419",
"expiryDate": "2022-05-28",
"mrp": 60.0,
"saleRate": 60.0,
"purchaseRate": 13.74,
"quantity": 500.0,
"storeName": "Main Store",
"newMrp": null,
"newSaleRate": null,
"newExpiryDate": null,
"newShortName": null,
"createdby": null,
"status": null
}
But only get not null value like "mrp": 60.0, "saleRate": 60.0
and "newSaleRate": null, this are not convert

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