在LightSwitch Entity/Table I中有一个称为" DisplayName"的计算字段,我将其用作该实体的摘要属性。计算的属性/字段包含名称,最后名,出生日期和主电话。这样:
partial void DisplayName_Compute(ref string result)
{
// Set result to the desired field value
result = FirstName + " " + LastName + " " + DOB+" "+PrimaryPhone;
在C#。
中在出生日期,DOB在实体/表中具有"日期"的数据类型。在桌面客户端应用程序中的ListDetail屏幕的列表列中显示记录为:
约翰·多伊(John Doe)01/17/1980 12:00 a.m.555-555-5555我想剥离时间,以便看起来像这样:
John Doe 01/17/1980 555-555-5555
这应该适用于您的方案:)
partial void DisplayName_Compute(ref string result)
{
//CREATE A DATETIME PARAMETER
DateTime theDate = Convert.ToDateTime(entity.DOB);
// Set result to the desired field value
result = FirstName + " " + LastName + " " + theDate.Date + " " + PrimaryPhone;
}
另外,这将是:
部分void displayname_compute(ref string result)
{
//CREATE A DATETIME PARAMETER
DateTime theDate = Convert.ToDateTime(entity.DOB);
// Set result to the desired field value
result = FirstName + " " + LastName + " " + theDate.ToString("dd.MM.yy") + " " + PrimaryPhone;
}
使用String.format使用所需的格式从多个参数生成字符串。在这种情况下,是:
var result=String.Format("{0} {1} {2:d} {3}",FirstName,LastName,DOB,PrimaryPhone");
这将返回使用客户文化的适当短期格式格式化的日期。如果您想将其用力编码为美国格式,则可以通过适当的文化:
var result=String.Format(CultureInfo.GetCultureInfo("en-US"),
"{0} {1} {2:d} {3}",FirstName,LastName,DOB,PrimaryPhone");