1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Security.Principal;
namespace System.Web.DynamicData.ModelProviders {
/// <summary>
/// Base provider class for tables.
/// Each provider type (e.g. Linq To Sql, Entity Framework, 3rd party) extends this class.
/// </summary>
public abstract class TableProvider {
private Type _rootEntityType;
private string _dataContextPropertyName;
internal TableProvider() {
// for unit testing
}
/// <summary>
/// ctor
/// </summary>
/// <param name="model">the model this table belongs to</param>
protected TableProvider(DataModelProvider model) {
if (model == null) {
throw new ArgumentNullException("model");
}
DataModel = model;
}
/// <summary>
/// readable representation
/// </summary>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
public override string ToString() {
// To help identifying objects in debugger
return Name ?? base.ToString();
}
/// <summary>
/// Provides access to attributes defined for the table represented by this provider.
/// </summary>
public virtual AttributeCollection Attributes {
get {
return GetTypeDescriptor().GetAttributes();
}
}
public virtual ICustomTypeDescriptor GetTypeDescriptor() {
return TypeDescriptor.GetProvider(EntityType).GetTypeDescriptor(EntityType);
}
/// <summary>
/// The name of the table. Typically, this is the name of the property in the data context class
/// </summary>
public virtual string Name { get; protected set; }
/// <summary>
/// The CLR type that represents this table
/// </summary>
public virtual Type EntityType { get; protected set; }
/// <summary>
/// The collection of columns in this table
/// </summary>
public abstract ReadOnlyCollection<ColumnProvider> Columns { get; }
/// <summary>
/// The IQueryable that returns the elements of this table
/// </summary>
public abstract IQueryable GetQuery(object context);
/// <summary>
/// The data model provider that this table is part of
/// </summary>
public DataModelProvider DataModel { get; internal set; }
/// <summary>
/// Get the value of a foreign key for a given row. By default, it just looks up a property by that name
/// </summary>
public virtual object EvaluateForeignKey(object row, string foreignKeyName) {
return System.Web.UI.DataBinder.GetPropertyValue(row, foreignKeyName);
}
/// <summary>
/// Return the parent type of this entity's inheritance hierarchy; if the type is at the top
/// of an inheritance hierarchy or does not have any inheritance, will return null.
/// </summary>
public virtual Type ParentEntityType { get; protected set; }
/// <summary>
/// Return the root type of this entity's inheritance hierarchy; if the type is at the top
/// of an inheritance hierarchy or does not have any inheritance, will return EntityType.
/// </summary>
public virtual Type RootEntityType {
get {
return _rootEntityType ?? EntityType;
}
protected set {
_rootEntityType = value;
}
}
/// <summary>
/// Name of table coming from the property on the data context. E.g. the value is "Products" for
/// a table that is part of the NorthwindDataContext.Products collection. If this value has not
/// been set, it will return the value of the Name property.
/// </summary>
public virtual string DataContextPropertyName {
get {
return _dataContextPropertyName ?? Name;
}
protected set {
_dataContextPropertyName = value;
}
}
/// <summary>
/// Returns whether the passed in user is allowed to delete items from the table
/// </summary>
public virtual bool CanDelete(IPrincipal principal) {
if (principal == null) {
throw new ArgumentNullException("principal");
}
return true;
}
/// <summary>
/// Returns whether the passed in user is allowed to insert into the table
/// </summary>
public virtual bool CanInsert(IPrincipal principal) {
if (principal == null) {
throw new ArgumentNullException("principal");
}
return true;
}
/// <summary>
/// Returns whether the passed in user is allowed to read from the table
/// </summary>
public virtual bool CanRead(IPrincipal principal) {
if (principal == null) {
throw new ArgumentNullException("principal");
}
return true;
}
/// <summary>
/// Returns whether the passed in user is allowed to make changes tothe table
/// </summary>
public virtual bool CanUpdate(IPrincipal principal) {
if (principal == null) {
throw new ArgumentNullException("principal");
}
return true;
}
}
}
|