从IEnumerable <restrictionaction>转换为EntitySet <restrictionaction>

时间:2018-09-28 00:56:12

标签: c# casting

我有一个EntitySet类,看起来像这样(删除了不必要的代码):

 public class EntitySet<RestrictionAction> : EntitySet, IEnumerable<RestrictionAction>
 {
    public DataTable DataTable { get; private set; }
    publicIEnumerable<RestrictionAction> GetEntitiesFrom(IEnumerable<DataRow> aDataRows) => aDataRows.Select(aDataRow => this[aDataRow]);
    public new IEnumerable<RestrictionAction> GetEntities(string aFilterExpression, string aSortOrder = null, DataViewRowState aDataViewRowState = DataViewRowState.CurrentRows) => GetEntitiesFrom(DataTable.Select(aFilterExpression, aSortOrder, aDataViewRowState));
 }

我有一行看起来像这样的代码:

EntitySet<RestrictionAction> df = (EntitySet<RestrictionAction>)restrictionActions.GetEntities($"{nameof(RestrictionAction.CompanyId)} = {dataRowView[nameof(RestrictionAction.CompanyId)]}");

我还没有运行我的代码,但是我相信当尝试将InvalidCastException转换为IEnumerable<RestrictionAction>时,它将抛出EntitySet<RestrictionAction>

有人知道我该怎么做吗?

0 个答案:

没有答案