【发布时间】:2020-04-04 21:35:40
【问题描述】:
我找到了解决问题的方法
public class Employee
{
public int? Id { get; set; }
public bool IsIdSelected { get; set; }
public string Name { get; set; }
public bool IsNameSelected { get; set; }
public string Address { get; set; }
public bool IsAddressSelected { get; set; }
}
private void OnExportButtonClick(object sender, RoutedEventArgs e)
{
// Now, concatinate all the selected cells
var str = string.Empty;
foreach (var emp in _collection)
{
if (emp.IsIdSelected)
str += string.Format("{0}, ", emp.Id);
if (emp.IsNameSelected)
str += string.Format("{0}, ", emp.Name);
if (emp.IsAddressSelected)
str += string.Format("{0}", emp.Address);
str += "\n";
}
// Instead of displaying this message you could export these cells to Excel
// in the format you need.
MessageBox.Show(str);
}
}
}
但是……
我的类生成实体包含这个:
public partial class People
{
public int Id { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
}
我无法向其中添加布尔字段,因为它破坏了逻辑并且实体核心不允许我这样做。
我该如何解决这个问题? 谢谢。
【问题讨论】:
-
永远不要在循环中连接
string。你应该在这里使用StringBuilder。此外,您的问题并不清楚您的问题是什么以及您正在寻求什么样的解决方案。 -
请把问题说清楚
标签: c# .net entity-framework