MVVMとWAFフレームワークを使用しています。 WAF Frameworkには、EntityCollectionというクラスがあります。誰かがIEnumberableをEntityCollectionにキャストする手助けができますか?
public sealed class EntityCollection<TEntity> : RelatedEnd, ICollection<TEntity>, IEnumerable<TEntity>, IEnumerable, IListSource where TEntity : class
{
public EntityCollection();
public int Count { get; }
public bool IsReadOnly { get; }
public void Add(TEntity entity);
public void Attach(IEnumerable<TEntity> entities);
public void Clear();
public bool Contains(TEntity entity);
public void CopyTo(TEntity[] array, int arrayIndex);
public ObjectQuery<TEntity> CreateSourceQuery();
public IEnumerator<TEntity> GetEnumerator();
public override void Load(MergeOption mergeOption);
public void OnCollectionDeserialized(StreamingContext context);
public void OnSerializing(StreamingContext context);
public bool Remove(TEntity entity);
}
しかし、私はLINQ TO XMLを使う必要があります。 GetExamProduced関数をチェックし、EntityCollectionがどこにあり、GetExercises(xml)からすべてを追加する必要があるかのプロパティExercisesがありますが、データ型のために問題があります。前もって感謝します。
EDIT: 状況は、GetExercises関数をExamsProducedからExecisesプロパティに戻す演習を挿入または追加したいと考えています。
私の問題はキャストです。 ExercisesプロパティはEntityCollectionデータ型であり、もう1つはIEnumerableです。 IEnumerableのすべての項目をEntityCollectionに挿入するにはどうすればよいですか。
public ExamProduced GetExamProduced(XElement xml)
{
var examProduced = new ExamProduced
{
ExamProducedID = (int)xml.Attribute("ExamID"),
Date = (DateTime)xml.Attribute("Date"),
Seed = (int)xml.Attribute("Seed"),
Exercises = GetExercises(xml)
};
return examProduced;
}
public EntityCollection<Exercise> GetExercises(XElement xml)
{
var objs =
from objective in xml.Descendants("Objective")
where (bool)objective.Attribute("Produced")
let id = (int)objective.Attribute("ID")
select new Exercise
{
ExerciseID = id,
MakeUp = (bool)objective.Attribute("MakeUp"),
Quantify = (byte)(int)objective.Attribute("Quantify"),
Score = (float)objective.Elements().Last().Attribute("Result")
};
return (EntityCollection<Exercise>)objs;
}
正確にどのような問題?キャスト例外はありますか? –
エラーが発生しましたか?またはロジックが間違っていますか?あなたの状況をより詳細に説明してください。 GetExercises(xml)からすべてを追加する必要があると言いました。すべては何ですか? –
編集を確認してください。 – Darf