Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / MetaForeignKeyColumn.cs / 1305376 / MetaForeignKeyColumn.cs
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Security.Permissions;
using System.Web.DynamicData.ModelProviders;
using System.Linq;
using System.Web.UI;
namespace System.Web.DynamicData {
///
/// A special column representing many-1 relationships
///
public class MetaForeignKeyColumn : MetaColumn, IMetaForeignKeyColumn {
// Maps a foreign key name to the name that should be used in a Linq expression for filtering
// i.e. the foreignkey name might be surfaced through a custom type descriptor e.g. CategoryID but we might really want to use
// Category.CategoryId in the expression
private Dictionary _foreignKeyFilterMapping;
public MetaForeignKeyColumn(MetaTable table, ColumnProvider entityMember)
: base(table, entityMember) {
}
///
/// Perform initialization logic for this column
///
internal protected override void Initialize() {
base.Initialize();
ParentTable = Model.GetTable(Provider.Association.ToTable.Name, Table.DataContextType);
CreateForeignKeyFilterMapping(ForeignKeyNames, ParentTable.PrimaryKeyNames, (foreignKey) => Table.EntityType.GetProperty(foreignKey) != null);
}
internal void CreateForeignKeyFilterMapping(IList foreignKeyNames, IList primaryKeyNames, Func propertyExists) {
// HACK: Some tests don't mock foreign key names, but this should never be the case at runtime
if (foreignKeyNames == null) {
return;
}
int pKIndex = 0;
foreach (string fkName in foreignKeyNames) {
if (!propertyExists(fkName)) {
if (_foreignKeyFilterMapping == null) {
_foreignKeyFilterMapping = new Dictionary();
}
_foreignKeyFilterMapping[fkName] = Name + "." + primaryKeyNames[pKIndex];
}
pKIndex++;
}
}
///
/// The parent table of the relationship (e.g. Categories in Products->Categories)
///
public MetaTable ParentTable {
get;
// internal for unit testing
internal set;
}
///
/// Returns true if this foriegn key column is part of the primary key of its table
/// e.g. Order and Product are PKs in the Order_Details table
///
public bool IsPrimaryKeyInThisTable {
get {
return Provider.Association.IsPrimaryKeyInThisTable;
}
}
///
/// This is used when saving the value of a foreign key, e.g. when selected from a drop down.
///
public void ExtractForeignKey(IDictionary dictionary, string value) {
if (String.IsNullOrEmpty(value)) {
// If the value is null, set all the FKs to null
foreach (string fkName in ForeignKeyNames) {
dictionary[fkName] = null;
}
}
else {
string[] fkValues = Misc.ParseCommaSeparatedString(value);
Debug.Assert(fkValues.Length == ForeignKeyNames.Count);
for (int i = 0; i < fkValues.Length; i++) {
dictionary[ForeignKeyNames[i]] = fkValues[i];
}
}
}
///
/// Return the value of all the foreign keys components for the passed in row
///
public IList
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- VerticalAlignConverter.cs
- SecurityRuntime.cs
- ConditionChanges.cs
- COAUTHINFO.cs
- ExpressionConverter.cs
- EFDataModelProvider.cs
- DbConnectionPoolIdentity.cs
- XmlDigitalSignatureProcessor.cs
- MetadataPropertyCollection.cs
- DNS.cs
- Imaging.cs
- OrderedDictionary.cs
- DesignerDataView.cs
- BufferModeSettings.cs
- SpecularMaterial.cs
- DataGridViewCell.cs
- HttpResponse.cs
- mda.cs
- StatusBar.cs
- IncrementalHitTester.cs
- CodeSnippetStatement.cs
- x509store.cs
- StateItem.cs
- CellNormalizer.cs
- SqlDataSourceView.cs
- UIAgentRequest.cs
- BuilderPropertyEntry.cs
- VideoDrawing.cs
- Color.cs
- XamlStream.cs
- BindingSource.cs
- HttpModulesSection.cs
- SqlDataSourceRefreshSchemaForm.cs
- EntityDataSourceSelectedEventArgs.cs
- ReferenceConverter.cs
- OrderedDictionary.cs
- DataProtection.cs
- WebPartTracker.cs
- TextDecorationLocationValidation.cs
- StorageInfo.cs
- MetadataPropertyvalue.cs
- CellQuery.cs
- ActivityMarkupSerializationProvider.cs
- CodeIndexerExpression.cs
- DependencyPropertyChangedEventArgs.cs
- UnsafeMethods.cs
- BaseCodeDomTreeGenerator.cs
- MetadataItemCollectionFactory.cs
- DbConvert.cs
- BitmapFrameEncode.cs
- CompiledQuery.cs
- CodeGenerator.cs
- OdbcConnectionFactory.cs
- DiscriminatorMap.cs
- TableCellCollection.cs
- SqlGatherProducedAliases.cs
- CryptoApi.cs
- DataBindEngine.cs
- TextBoxDesigner.cs
- TTSEngineTypes.cs
- BuildTopDownAttribute.cs
- XmlSchemaResource.cs
- RecipientInfo.cs
- DataGridViewRowsRemovedEventArgs.cs
- CrossAppDomainChannel.cs
- SpecialFolderEnumConverter.cs
- BuildProvidersCompiler.cs
- Journal.cs
- XmlDataCollection.cs
- OleDbRowUpdatingEvent.cs
- NetNamedPipeBinding.cs
- HostingEnvironmentException.cs
- BindingExpressionBase.cs
- IgnoreDeviceFilterElement.cs
- DeadCharTextComposition.cs
- DetailsViewRow.cs
- FlowDocumentView.cs
- ProxyWebPartConnectionCollection.cs
- TemplateControlBuildProvider.cs
- DelegateSerializationHolder.cs
- ThreadInterruptedException.cs
- JavaScriptString.cs
- AmbientValueAttribute.cs
- ResourcesBuildProvider.cs
- InstanceStoreQueryResult.cs
- ContentOperations.cs
- LayoutDump.cs
- DirectoryObjectSecurity.cs
- TypedDataSetSchemaImporterExtension.cs
- AttributeCollection.cs
- EdmRelationshipNavigationPropertyAttribute.cs
- ComponentEvent.cs
- TypeSystemHelpers.cs
- EncryptedData.cs
- IndentedTextWriter.cs
- ItemTypeToolStripMenuItem.cs
- File.cs
- OutputCacheProfile.cs
- AutomationEvent.cs
- InputBindingCollection.cs