[英]How to return array of data as return type in my linq query?
以下是我的課程。 類的返回類型應該是CpsResponse,但我不知道如何將類放在我的類返回類型中。 我對編程世界很陌生。
public class CpsResponse
{
private CustomerProfile[] customerProfileField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("CustomerProfile")]
public CustomerProfile[] CustomerProfile
{
get
{
return this.customerProfileField;
}
set
{
this.customerProfileField = value;
}
}
}
/// <remarks/>
public class CustomerProfile
{
private CustomerIdentifier customerIdentifierField;
private string emailField;
private string titleField;
private string firstNameField;
/// <remarks/>
public CustomerIdentifier CustomerIdentifier
{
get
{
return this.customerIdentifierField;
}
set
{
this.customerIdentifierField = value;
}
}
/// <remarks/>
public string Email
{
get
{
return this.emailField;
}
set
{
this.emailField = value;
}
}
/// <remarks/>
public string Title
{
get
{
return this.titleField;
}
set
{
this.titleField = value;
}
}
/// <remarks/>
public string FirstName
{
get
{
return this.firstNameField;
}
set
{
this.firstNameField = value;
}
}
}
/// <remarks/>
public class CustomerIdentifier
{
private string uniqueCustomerIdentifierField;
private string versionField;
/// <remarks/>
public string UniqueCustomerIdentifier
{
get
{
return this.uniqueCustomerIdentifierField;
}
set
{
this.uniqueCustomerIdentifierField = value;
}
}
/// <remarks/>
public string Version
{
get
{
return this.versionField;
}
set
{
this.versionField = value;
}
}
}
我從db獲取值到對象'customerData'。 現在我想返回值,我的返回類型應該是CpsResponse。 我怎樣才能做到這一點?
var customerResult = (from a in customerData
select new CpsResponse {//what actually I should //write here I don’t know, Please help});
請只做那些需要的。
在不知道CpsResponse
的定義的情況下,我們無法准確回答這個問題,但基本上它看起來像:
List<CpsResponse> myList = (from a in customerdata
select new CpsResonse { id = a.CustomerIdentifier, email = a.emailField }).ToList()
您可以使用DB中所需的字段選擇new並CpsResponse
的屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.