public override T GetModel <T>(string fieldName, SPModelCollection parentCollection) { if (this.ListItemAdapater != null) { return(this.ListItemAdapater.GetModel <T>(fieldName, parentCollection)); } return(base.GetModel <T>(fieldName, parentCollection)); }
/// <summary> /// Gets a model object from a Lookup field. /// The same instance representing the same foreign list item is returned when the same <paramref name="parentCollection"/> is supplied. /// </summary> /// <typeparam name="T">Type of model object.</typeparam> /// <param name="fieldName">Field name.</param> /// <param name="parentCollection">An <see cref="SPModelCollection"/> object where the returned model object is cached in the collection.</param> /// <returns>Value in the specified field represented by a model object.</returns> public virtual T GetModel <T>(string fieldName, SPModelCollection parentCollection) { object value = this[fieldName]; if (value != null) { try { SPFieldLookupValue u = new SPFieldLookupValue(value.ToString()); return(parentCollection.TryGetCachedModel <T>(this, fieldName, u.LookupId).FirstOrDefault()); } catch { } } return(default(T)); }
/// <summary> /// Gets a collection of model objects from a Lookup field. /// The same instance representing the same foreign list item is returned when the same <paramref name="parentCollection"/> is supplied. /// </summary> /// <typeparam name="T">Type of model object.</typeparam> /// <param name="fieldName">Field name.</param> /// <param name="parentCollection">An <see cref="SPModelCollection"/> object where the returned model object is cached in the collection.</param> /// <returns>A collection of model objects.</returns> protected virtual IList <T> GetModelCollectionInternal <T>(string fieldName, SPModelCollection parentCollection) { Collection <T> collection = new Collection <T>(); object value = this[fieldName]; if (value != null) { try { SPFieldLookupValueCollection values = CommonHelper.TryCastOrDefault <SPFieldLookupValueCollection>(value) ?? new SPFieldLookupValueCollection(value.ToString()); foreach (T item in parentCollection.TryGetCachedModel <T>(this, fieldName, values.Select(u => u.LookupId).ToArray())) { collection.Add(item); } } catch { } } return(collection); }
public object Execute() { if (this.Manager == null) { throw new InvalidOperationException(); } if (this.Manager.ImplicitQueryMode == SPModelImplicitQueryMode.None) { return(projector(emptyArray, args)); } SPModelQuery query = ApplyFilters(); if (query.Expression == Caml.False) { return(projector(emptyArray, args)); } if (executeMode == SPModelQueryExecuteMode.Count) { return(this.Manager.GetCount(query)); } SPModelCollection collection = this.Manager.GetItems(query); return(projector(collection, args)); }
protected override IList <T> GetModelCollectionInternal <T>(string fieldName, SPModelCollection parentCollection) { if (this.ListItemAdapater != null) { return(this.ListItemAdapater.GetModelCollection <T>(fieldName, parentCollection)); } return(base.GetModelCollectionInternal <T>(fieldName, parentCollection)); }
public ReadOnlyCollection <T> GetModelCollectionReadOnly <T>(string fieldName, SPModelCollection parentCollection) { return(new ReadOnlyCollection <T>(GetModelCollectionInternal <T>(fieldName, parentCollection))); }
public IList <T> GetModelCollection <T>(string fieldName, SPModelCollection parentCollection) { return(CreateNotifyingCollection(fieldName, GetModelCollectionInternal <T>(fieldName, parentCollection), (s, e) => OnModelCollectionChanged(s, fieldName))); }