我的代码是如何从类型为Table的对象中删除元素?
if (selectedOrgName != "All")
{
// Get the orgid corresponding to the selected organization
var selectedOrgId = PD.orgs.FirstOrDefault(o => o.orgname == selectedOrgName);
// Return error message if no such oranization name exists
if (selectedOrgId == null)
{
return Content("Couldn't find row for organization '" + selectedOrgName +
"' in the database.");
}
foreach (var f in PD.files) if (f.orgid != selectedOrgId.orgid) f.Delete();
} // if search is filtered by a specific organization
除了Delete()
不被编译器识别。奇怪,因为this guy发布了相应的代码,并表示它的工作。我真正想要什么功能?
的PD.files
是Table<AssetFile>
其中AssetFile
被定义为
[Table(Name = "files")]
public class AssetFile
{
public AssetFile() { }
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int fileid { get; set; }
[Column]
public int orgid { get; set; }
[Column]
public int catid { get; set; }
[Column]
public string filename { get; set; }
}
什么是PD.files类型? –
'表'其中'AssetFile'由'[表(名称= “文件”)] 公共类AssetFile { 公共AssetFile() { } [柱(IsPrimaryKey =真,IsDbGenerated =定义true)] public int fileid {get;组; } [专栏] public int orgid {get;组; } [专栏] public int catid {get;组; } [Column] public string filename {get;组; } } ' –
user4905335
链接的问题是关于DataTable而不是表。 –