Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / ModelProviders / EFTableProvider.cs / 1305376 / EFTableProvider.cs
using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data.Metadata.Edm; using System.Data.Objects; using System.Linq; using System.Reflection; namespace System.Web.DynamicData.ModelProviders { internal sealed class EFTableProvider : TableProvider { private ReadOnlyCollection_roColumns; public EFTableProvider(EFDataModelProvider dataModel, EntitySet entitySet, EntityType entityType, Type entityClrType, Type parentEntityClrType, Type rootEntityClrType, string name) : base(dataModel) { EntityType = entityClrType; Name = name; DataContextPropertyName = entitySet.Name; ParentEntityType = parentEntityClrType; RootEntityType = rootEntityClrType; var genericMethod = DataModel.ContextType.GetMethod("CreateQuery"); CreateQueryMethod = genericMethod.MakeGenericMethod(EntityType); CreateQueryString = CreateEntitySqlQueryString(entitySet); var keyMembers = entityType.KeyMembers; // columns (entity properties) // note 1: keys are also available through es.ElementType.KeyMembers // note 2: this includes "nav properties", kind of fancy, two-way relationship objects var columns = new List (); foreach (EdmMember m in entityType.Members) { if (EFColumnProvider.IsSupportedEdmMemberType(m) && IsPublicProperty(entityClrType, m.Name)) { EFColumnProvider entityMember = new EFColumnProvider(entityType, this, m, keyMembers.Contains(m)); columns.Add(entityMember); } } _roColumns = new ReadOnlyCollection (columns); } private static bool IsPublicProperty(Type entityClrType, string propertyName) { var property = entityClrType.GetProperty(propertyName); return property != null && property.GetGetMethod() != null; } private MethodInfo CreateQueryMethod { get; set; } private string CreateQueryString { get; set; } private static string CreateEntitySqlQueryString(EntitySet entitySet) { // Qualify the entity set name with the container name (in case the ObjectContext's default // container name is not set or has an unexpected value) return QuoteEntitySqlIdentifier(entitySet.EntityContainer.Name) + "." + QuoteEntitySqlIdentifier(entitySet.Name); } private static string QuoteEntitySqlIdentifier(string identifier) { // Enclose in square brackets and escape the one reserved character (]) return "[" + identifier.Replace("]", "]]") + "]"; } public override ReadOnlyCollection Columns { get { return _roColumns; } } public override IQueryable GetQuery(object context) { return (IQueryable)CreateQueryMethod.Invoke(context, new object[] { CreateQueryString, new ObjectParameter[0] }); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data.Metadata.Edm; using System.Data.Objects; using System.Linq; using System.Reflection; namespace System.Web.DynamicData.ModelProviders { internal sealed class EFTableProvider : TableProvider { private ReadOnlyCollection _roColumns; public EFTableProvider(EFDataModelProvider dataModel, EntitySet entitySet, EntityType entityType, Type entityClrType, Type parentEntityClrType, Type rootEntityClrType, string name) : base(dataModel) { EntityType = entityClrType; Name = name; DataContextPropertyName = entitySet.Name; ParentEntityType = parentEntityClrType; RootEntityType = rootEntityClrType; var genericMethod = DataModel.ContextType.GetMethod("CreateQuery"); CreateQueryMethod = genericMethod.MakeGenericMethod(EntityType); CreateQueryString = CreateEntitySqlQueryString(entitySet); var keyMembers = entityType.KeyMembers; // columns (entity properties) // note 1: keys are also available through es.ElementType.KeyMembers // note 2: this includes "nav properties", kind of fancy, two-way relationship objects var columns = new List (); foreach (EdmMember m in entityType.Members) { if (EFColumnProvider.IsSupportedEdmMemberType(m) && IsPublicProperty(entityClrType, m.Name)) { EFColumnProvider entityMember = new EFColumnProvider(entityType, this, m, keyMembers.Contains(m)); columns.Add(entityMember); } } _roColumns = new ReadOnlyCollection (columns); } private static bool IsPublicProperty(Type entityClrType, string propertyName) { var property = entityClrType.GetProperty(propertyName); return property != null && property.GetGetMethod() != null; } private MethodInfo CreateQueryMethod { get; set; } private string CreateQueryString { get; set; } private static string CreateEntitySqlQueryString(EntitySet entitySet) { // Qualify the entity set name with the container name (in case the ObjectContext's default // container name is not set or has an unexpected value) return QuoteEntitySqlIdentifier(entitySet.EntityContainer.Name) + "." + QuoteEntitySqlIdentifier(entitySet.Name); } private static string QuoteEntitySqlIdentifier(string identifier) { // Enclose in square brackets and escape the one reserved character (]) return "[" + identifier.Replace("]", "]]") + "]"; } public override ReadOnlyCollection Columns { get { return _roColumns; } } public override IQueryable GetQuery(object context) { return (IQueryable)CreateQueryMethod.Invoke(context, new object[] { CreateQueryString, new ObjectParameter[0] }); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SortDescriptionCollection.cs
- TextRangeSerialization.cs
- Pens.cs
- RC2.cs
- AddressAlreadyInUseException.cs
- TrustDriver.cs
- MimeFormatter.cs
- GridItemCollection.cs
- BStrWrapper.cs
- NonParentingControl.cs
- XmlSchemaSimpleTypeRestriction.cs
- Vector3DAnimationBase.cs
- StackBuilderSink.cs
- Identifier.cs
- RequestQueryProcessor.cs
- FormsAuthenticationEventArgs.cs
- Maps.cs
- SpecularMaterial.cs
- ComponentResourceKey.cs
- QilValidationVisitor.cs
- oledbmetadatacollectionnames.cs
- CustomErrorsSection.cs
- SplitContainer.cs
- ObjectDataSourceChooseTypePanel.cs
- PackWebRequest.cs
- SQLByteStorage.cs
- LicenseManager.cs
- DecimalAnimationUsingKeyFrames.cs
- assertwrapper.cs
- PeerApplicationLaunchInfo.cs
- ErrorRuntimeConfig.cs
- WMICapabilities.cs
- Random.cs
- ToolStripContentPanel.cs
- SqlBulkCopyColumnMappingCollection.cs
- WebPartConnectionsDisconnectVerb.cs
- FilteredReadOnlyMetadataCollection.cs
- Int32Rect.cs
- entitydatasourceentitysetnameconverter.cs
- MemoryStream.cs
- ServiceHost.cs
- ActivityDesignerResources.cs
- Scheduler.cs
- EventDescriptor.cs
- MetabaseServerConfig.cs
- MonikerProxyAttribute.cs
- ComponentCommands.cs
- LocalFileSettingsProvider.cs
- safex509handles.cs
- ActiveDocumentEvent.cs
- GridViewCancelEditEventArgs.cs
- WindowsRichEditRange.cs
- CompilationPass2TaskInternal.cs
- DbDataRecord.cs
- JapaneseCalendar.cs
- PageStatePersister.cs
- DocumentsTrace.cs
- XmlSequenceWriter.cs
- TypedColumnHandler.cs
- Empty.cs
- LambdaCompiler.Logical.cs
- ManualResetEvent.cs
- ToolStripMenuItemDesigner.cs
- ConfigPathUtility.cs
- ContextMenuAutomationPeer.cs
- XpsManager.cs
- CompositionDesigner.cs
- FastEncoderWindow.cs
- ProvidersHelper.cs
- Utils.cs
- DoubleKeyFrameCollection.cs
- LocatorPartList.cs
- InternalConfigEventArgs.cs
- Control.cs
- XhtmlBasicTextViewAdapter.cs
- X509SecurityTokenAuthenticator.cs
- LoadRetryHandler.cs
- ListDictionaryInternal.cs
- DataDocumentXPathNavigator.cs
- Command.cs
- AbsoluteQuery.cs
- CompiledAction.cs
- MobileControlsSectionHandler.cs
- CloudCollection.cs
- SkipStoryboardToFill.cs
- ApplicationServiceHelper.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- wmiprovider.cs
- CommonObjectSecurity.cs
- SqlFileStream.cs
- Registry.cs
- PhysicalAddress.cs
- EmptyEnumerable.cs
- ActivityExecutionContextCollection.cs
- TypeExtension.cs
- SmiEventSink_DeferedProcessing.cs
- XmlNodeReader.cs
- COAUTHINFO.cs
- RootDesignerSerializerAttribute.cs
- MultipleViewProviderWrapper.cs