Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / ModelProviders / DLinqAssociationProvider.cs / 1305376 / DLinqAssociationProvider.cs
using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data.Linq.Mapping; using System.Linq; using System.Reflection; using System.Diagnostics; using System.Collections.Specialized; using System.Collections; using System.Globalization; namespace System.Web.DynamicData.ModelProviders { internal sealed class DLinqAssociationProvider : AssociationProvider { public DLinqAssociationProvider(DLinqColumnProvider column) { FromColumn = column; MetaAssociation association = column.Member.Association; SetOtherEndOfAssociation(association); SetDirection(association); Debug.Assert(Direction != AssociationDirection.ManyToMany, "Many to Many is not supported by Linq to SQL"); SetAssociationKeyInfo(association); } private void SetAssociationKeyInfo(MetaAssociation association) { DLinqColumnProvider column = (DLinqColumnProvider)FromColumn; ListforeignKeyNames = new List (); int count = column.Member.Association.ThisKey.Count; for (int i = 0; i < count; i++) { MetaDataMember thisKeyMetaDataMember = column.Member.Association.ThisKey[i]; MetaDataMember otherKeyMetaDataMember = column.Member.Association.OtherKey[i]; DLinqColumnProvider thisEntityMemberComponent = FindColumn(column.Table, thisKeyMetaDataMember.Name); if (ShouldRemoveThisAssociation(association)) { column.ShouldRemove = true; return; } foreignKeyNames.Add(thisEntityMemberComponent.Name); if (thisEntityMemberComponent.IsPrimaryKey) { IsPrimaryKeyInThisTable = true; } if (association.IsForeignKey) { thisEntityMemberComponent.IsForeignKeyComponent = true; } } ForeignKeyNames = new ReadOnlyCollection (foreignKeyNames); } private bool ShouldRemoveThisAssociation(MetaAssociation association) { if (Direction == AssociationDirection.ManyToOne && !association.OtherKeyIsPrimaryKey) { return true; } if (Direction == AssociationDirection.OneToMany && !association.ThisKeyIsPrimaryKey) { return true; } if (Direction == AssociationDirection.OneToOne) { if (!association.IsForeignKey && !association.ThisKeyIsPrimaryKey) { return true; } if (association.IsForeignKey && !association.OtherKeyIsPrimaryKey) { return true; } } return false; } private void SetOtherEndOfAssociation(MetaAssociation association) { DLinqTableProvider entityMemberParentEntity = (DLinqTableProvider)FromColumn.Table; DLinqDataModelProvider parentEntityDataContext = (DLinqDataModelProvider)entityMemberParentEntity.DataModel; if (association.OtherMember != null) { ToColumn = parentEntityDataContext.ColumnLookup[(PropertyInfo)association.OtherMember.Member]; } else { ToTable = ((DLinqDataModelProvider)FromColumn.Table.DataModel).DLinqTables.Single(tp => tp.EntityType == association.OtherType.Type); } } private static DLinqColumnProvider FindColumn(TableProvider table, String columnName) { // return (DLinqColumnProvider)table.Columns.First(member => member.Name.Equals(columnName)); } private void SetDirection(MetaAssociation association) { if (association.IsMany) { Direction = AssociationDirection.OneToMany; } else if (association.OtherMember == null || association.OtherMember.Association.IsMany) { // there might not be the other member if this is a one-sided association Direction = AssociationDirection.ManyToOne; } else { Direction = AssociationDirection.OneToOne; } } public override string GetSortExpression(ColumnProvider sortColumn) { return GetSortExpression(sortColumn, "{0}.{1}"); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Control.cs
- UrlMappingCollection.cs
- InteropBitmapSource.cs
- VerificationAttribute.cs
- UIHelper.cs
- ObjectQueryState.cs
- TableLayoutRowStyleCollection.cs
- ActivationArguments.cs
- BooleanToVisibilityConverter.cs
- PropertyDescriptor.cs
- DataList.cs
- HtmlButton.cs
- CngKeyCreationParameters.cs
- _NestedSingleAsyncResult.cs
- DashStyle.cs
- IdentityManager.cs
- FontCacheLogic.cs
- WpfXamlType.cs
- DelegateSerializationHolder.cs
- NativeWrapper.cs
- BitmapEffectDrawing.cs
- SignedXml.cs
- NoneExcludedImageIndexConverter.cs
- ScalarConstant.cs
- ipaddressinformationcollection.cs
- DirtyTextRange.cs
- JoinQueryOperator.cs
- _ListenerResponseStream.cs
- ValidatedControlConverter.cs
- XmlIncludeAttribute.cs
- HtmlFormParameterWriter.cs
- ScriptComponentDescriptor.cs
- ManagementDateTime.cs
- InfoCardTraceRecord.cs
- UIElementPropertyUndoUnit.cs
- WebEventCodes.cs
- SecurityUtils.cs
- CharacterBufferReference.cs
- WebUtil.cs
- ResourceExpressionEditor.cs
- TreeNodeStyleCollection.cs
- InternalResources.cs
- RoleGroupCollection.cs
- SqlFunctionAttribute.cs
- View.cs
- PropertyPath.cs
- VisualStyleElement.cs
- WebRequestModulesSection.cs
- ContentPosition.cs
- RotateTransform.cs
- CachedCompositeFamily.cs
- MobileSysDescriptionAttribute.cs
- ByteRangeDownloader.cs
- _ListenerResponseStream.cs
- BinaryWriter.cs
- Win32PrintDialog.cs
- MessageDirection.cs
- EditCommandColumn.cs
- Vector3DValueSerializer.cs
- DependencyPropertyDescriptor.cs
- WebControlAdapter.cs
- ArrayEditor.cs
- WebPartsPersonalizationAuthorization.cs
- ArrayTypeMismatchException.cs
- SqlAggregateChecker.cs
- StreamGeometry.cs
- StreamResourceInfo.cs
- X509AsymmetricSecurityKey.cs
- UpDownEvent.cs
- CqlLexer.cs
- SafeSystemMetrics.cs
- TraceSection.cs
- EntityTypeBase.cs
- LinkButton.cs
- ConfigDefinitionUpdates.cs
- XsltCompileContext.cs
- RequestSecurityToken.cs
- KeyGesture.cs
- Stroke.cs
- HttpWrapper.cs
- SHA1CryptoServiceProvider.cs
- DataGridViewIntLinkedList.cs
- TableAutomationPeer.cs
- ObjectSecurity.cs
- EncodingDataItem.cs
- CapabilitiesRule.cs
- ValidationPropertyAttribute.cs
- GZipStream.cs
- ToolStripRenderEventArgs.cs
- ObjectIDGenerator.cs
- RegexCharClass.cs
- OdbcTransaction.cs
- HMACSHA384.cs
- RegionInfo.cs
- ConfigurationManagerInternal.cs
- ProcessThreadDesigner.cs
- XmlExtensionFunction.cs
- EncodingInfo.cs
- GridViewColumnCollection.cs
- FrugalList.cs