问题
I have a data table which looks like
id name age emailId
X bill 20 bill@abc.com
y john 19 bob@abc.com
on client side application
public class myTabble { public string Id { get; set; }
[JsonProperty(PropertyName = "name")]
public string name { get; set; }
[JsonProperty(PropertyName = "age")]
public int age { get; set; }
[JsonProperty(PropertyName = "email")]
public string email { get; set; }
I am trying to store the name of the user having email id bob@abc.com by
var names = await todoTable
.Where(t => t.email == "bob@abc.com")
.Select(t => t.fname)
.ToCollectionAsync();
string myName = Convert.ToString(names);
but it is not working. How can I do this please help.
回答1:
Calling ToCollectionAsync
will give you a collection object (an ObservableCollection), one which you can use to bind the results with a UI control (such as a list view). If you want to programmatically get a value, you should use one of the other methods to retrieve data from the table, either ToListAsync
or ToCollectionAsync
:
var names = await todoTable
.Where(t => t.email == "bob@abc.com")
.Select(t => t.fname)
.ToEnumerableAsync();
var myName = name.FirstOrDefault(); // name will be null if not found
来源:https://stackoverflow.com/questions/21087755/specific-value-from-azure-mobile-services-table