Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataWebControls / System / Data / WebControls / EntityDataSourceReferenceGroup.cs / 1 / EntityDataSourceReferenceGroup.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.EntityClient;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.ComponentModel;
using System.Data.Common;
using System.Data.Objects.DataClasses;
using System.Data.Objects;
using System.Data;
namespace System.Web.UI.WebControls
{
///
/// Groups together reference columns pointing at the same association end.
///
internal abstract class EntityDataSourceReferenceGroup
{
private readonly AssociationSetEnd end;
protected EntityDataSourceReferenceGroup(AssociationSetEnd end)
{
EntityDataSourceUtil.CheckArgumentNull(end, "end");
this.end = end;
}
internal AssociationSetEnd End { get { return this.end; } }
internal static EntityDataSourceReferenceGroup Create(Type entityType, AssociationSetEnd end)
{
EntityDataSourceUtil.CheckArgumentNull(entityType, "entityType");
Type groupType = typeof(EntityDataSourceReferenceGroup<>).MakeGenericType(entityType);
return (EntityDataSourceReferenceGroup)Activator.CreateInstance(groupType, new object[] { end });
}
internal abstract void SetKeyValues(EntityDataSourceWrapper wrapper, Dictionary newKeyValues);
internal abstract EntityKey GetEntityKey(IEntityWithRelationships entity);
}
internal class EntityDataSourceReferenceGroup : EntityDataSourceReferenceGroup
where T : class, IEntityWithRelationships
{
public EntityDataSourceReferenceGroup(AssociationSetEnd end)
: base(end)
{
}
internal override void SetKeyValues(EntityDataSourceWrapper wrapper, Dictionary newKeyValues)
{
EntityDataSourceUtil.CheckArgumentNull(wrapper, "wrapper");
EntityReference reference = GetRelatedReference((IEntityWithRelationships)wrapper.WrappedEntity);
EntityKey originalEntityKeys = reference.EntityKey;
if (null != newKeyValues)
{
if(null != originalEntityKeys)
{
// mix the missing keys from the original values
foreach (var originalEntityKey in originalEntityKeys.EntityKeyValues)
{
object newKeyValue;
if (newKeyValues.TryGetValue(originalEntityKey.Key, out newKeyValue))
{
// if any part of the key is null, the EntityKey is null
if (null == newKeyValue)
{
newKeyValues = null;
break;
}
}
else
{
// add the original value for this partial key since it is not saved in the viewstate
newKeyValues.Add(originalEntityKey.Key, originalEntityKey.Value);
}
}
}
else
{
// what we have in the newKeyValues should be sufficient to set the key
// but if any value is null, the whole key is null
foreach (var newKey in newKeyValues)
{
if (null == newKey.Value)
{
newKeyValues = null;
break;
}
}
}
}
if (null == newKeyValues)
{
// if the entity key is a compound key, and if any partial key is null, then the entitykey is null
reference.EntityKey = null;
}
else
{
reference.EntityKey = new EntityKey(EntityDataSourceUtil.GetQualifiedEntitySetName(End.EntitySet), (IEnumerable>)newKeyValues);
}
}
internal override EntityKey GetEntityKey(IEntityWithRelationships entity)
{
EntityKey key = GetRelatedReference(entity).EntityKey;
return key;
}
private EntityReference GetRelatedReference(IEntityWithRelationships entity)
{
EntityReference reference = entity.RelationshipManager.GetRelatedReference(
this.End.ParentAssociationSet.ElementType.FullName,
this.End.CorrespondingAssociationEndMember.Name);
return reference;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.EntityClient;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.ComponentModel;
using System.Data.Common;
using System.Data.Objects.DataClasses;
using System.Data.Objects;
using System.Data;
namespace System.Web.UI.WebControls
{
///
/// Groups together reference columns pointing at the same association end.
///
internal abstract class EntityDataSourceReferenceGroup
{
private readonly AssociationSetEnd end;
protected EntityDataSourceReferenceGroup(AssociationSetEnd end)
{
EntityDataSourceUtil.CheckArgumentNull(end, "end");
this.end = end;
}
internal AssociationSetEnd End { get { return this.end; } }
internal static EntityDataSourceReferenceGroup Create(Type entityType, AssociationSetEnd end)
{
EntityDataSourceUtil.CheckArgumentNull(entityType, "entityType");
Type groupType = typeof(EntityDataSourceReferenceGroup<>).MakeGenericType(entityType);
return (EntityDataSourceReferenceGroup)Activator.CreateInstance(groupType, new object[] { end });
}
internal abstract void SetKeyValues(EntityDataSourceWrapper wrapper, Dictionary newKeyValues);
internal abstract EntityKey GetEntityKey(IEntityWithRelationships entity);
}
internal class EntityDataSourceReferenceGroup : EntityDataSourceReferenceGroup
where T : class, IEntityWithRelationships
{
public EntityDataSourceReferenceGroup(AssociationSetEnd end)
: base(end)
{
}
internal override void SetKeyValues(EntityDataSourceWrapper wrapper, Dictionary newKeyValues)
{
EntityDataSourceUtil.CheckArgumentNull(wrapper, "wrapper");
EntityReference reference = GetRelatedReference((IEntityWithRelationships)wrapper.WrappedEntity);
EntityKey originalEntityKeys = reference.EntityKey;
if (null != newKeyValues)
{
if(null != originalEntityKeys)
{
// mix the missing keys from the original values
foreach (var originalEntityKey in originalEntityKeys.EntityKeyValues)
{
object newKeyValue;
if (newKeyValues.TryGetValue(originalEntityKey.Key, out newKeyValue))
{
// if any part of the key is null, the EntityKey is null
if (null == newKeyValue)
{
newKeyValues = null;
break;
}
}
else
{
// add the original value for this partial key since it is not saved in the viewstate
newKeyValues.Add(originalEntityKey.Key, originalEntityKey.Value);
}
}
}
else
{
// what we have in the newKeyValues should be sufficient to set the key
// but if any value is null, the whole key is null
foreach (var newKey in newKeyValues)
{
if (null == newKey.Value)
{
newKeyValues = null;
break;
}
}
}
}
if (null == newKeyValues)
{
// if the entity key is a compound key, and if any partial key is null, then the entitykey is null
reference.EntityKey = null;
}
else
{
reference.EntityKey = new EntityKey(EntityDataSourceUtil.GetQualifiedEntitySetName(End.EntitySet), (IEnumerable>)newKeyValues);
}
}
internal override EntityKey GetEntityKey(IEntityWithRelationships entity)
{
EntityKey key = GetRelatedReference(entity).EntityKey;
return key;
}
private EntityReference GetRelatedReference(IEntityWithRelationships entity)
{
EntityReference reference = entity.RelationshipManager.GetRelatedReference(
this.End.ParentAssociationSet.ElementType.FullName,
this.End.CorrespondingAssociationEndMember.Name);
return reference;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HTMLTagNameToTypeMapper.cs
- BuildProvidersCompiler.cs
- OleDbPropertySetGuid.cs
- SQLBoolean.cs
- ReliableSessionBindingElementImporter.cs
- DurableEnlistmentState.cs
- MimePart.cs
- Bits.cs
- ConfigurationElementProperty.cs
- ipaddressinformationcollection.cs
- RepeaterItemEventArgs.cs
- Path.cs
- ListComponentEditor.cs
- AuthenticateEventArgs.cs
- CreationContext.cs
- KeyEventArgs.cs
- Dictionary.cs
- PropertyTab.cs
- InvalidWMPVersionException.cs
- ModelFunction.cs
- ObjectStateManagerMetadata.cs
- XamlTemplateSerializer.cs
- EntityDataSource.cs
- ParameterBuilder.cs
- SqlSelectClauseBuilder.cs
- MailMessageEventArgs.cs
- CodeDomSerializerException.cs
- RowUpdatedEventArgs.cs
- MailWebEventProvider.cs
- SymmetricAlgorithm.cs
- OptionalMessageQuery.cs
- FullTextBreakpoint.cs
- BitmapEffectGroup.cs
- PeerCustomResolverSettings.cs
- ColorTransformHelper.cs
- HashSetDebugView.cs
- BlurBitmapEffect.cs
- CollectionBuilder.cs
- DataSet.cs
- RetriableClipboard.cs
- ExpressionLink.cs
- TextViewDesigner.cs
- ExpressionServices.cs
- SetterBaseCollection.cs
- SQLInt64Storage.cs
- WsatConfiguration.cs
- EndOfStreamException.cs
- CommandLibraryHelper.cs
- PostBackTrigger.cs
- DebugViewWriter.cs
- FileDialog_Vista_Interop.cs
- DefaultParameterValueAttribute.cs
- WindowsRebar.cs
- SerializationAttributes.cs
- ProcessModuleCollection.cs
- ListViewInsertEventArgs.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- NonValidatingSecurityTokenAuthenticator.cs
- FormsAuthenticationTicket.cs
- ReliableSessionElement.cs
- DoubleLinkList.cs
- RepeaterItemEventArgs.cs
- PropertyDescriptorComparer.cs
- SqlUDTStorage.cs
- SessionEndingCancelEventArgs.cs
- DependencyProperty.cs
- QuaternionAnimation.cs
- WrapperEqualityComparer.cs
- SchemaAttDef.cs
- MDIClient.cs
- RemotingException.cs
- SqlCommandSet.cs
- TextBoxBase.cs
- DBSqlParserTableCollection.cs
- LocalizedNameDescriptionPair.cs
- TreeSet.cs
- ConfigurationManagerHelper.cs
- ValueConversionAttribute.cs
- DispatcherTimer.cs
- TrackingLocationCollection.cs
- UnmanagedMemoryStream.cs
- SerializableAttribute.cs
- ProvidersHelper.cs
- CodeTypeDelegate.cs
- FixedBufferAttribute.cs
- FileIOPermission.cs
- MenuAutoFormat.cs
- EditorPartCollection.cs
- SafeHandle.cs
- DbProviderFactory.cs
- XmlChoiceIdentifierAttribute.cs
- EntityCommandExecutionException.cs
- RightsManagementEncryptionTransform.cs
- ContextMarshalException.cs
- EntityCommandExecutionException.cs
- PointKeyFrameCollection.cs
- ZipPackage.cs
- PenLineCapValidation.cs
- SkewTransform.cs
- NumericUpDownAccelerationCollection.cs