Я использую MVVM с WAF-фреймворком. WAF Framework содержит класс с именем EntityCollection<T>
:
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, у меня есть свойство Exercises, где EntityCollection<Exercise>
, и мне нужно добавить все из GetExercises (xml), но у меня возникают проблемы, потому что типы данных.
EDIT:
Ситуация такова, что я хотел бы вставить или добавить упражнения, которые возвращают функцию GetExercises, в свойство Exercises из ExamProduced.
Моя проблема - актерский состав. Свойство Exercises имеет тип данных EntityCollection<Exercise>
, а другое - 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;
}