Code:
/ 4.0 / 4.0 / untmp / 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.
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
- Schema.cs
- TemplateAction.cs
- QilList.cs
- OleDbParameter.cs
- DataRecord.cs
- TransformerInfo.cs
- XmlSchemaProviderAttribute.cs
- ErrorEventArgs.cs
- PowerStatus.cs
- ProcessInputEventArgs.cs
- ConfigurationLocation.cs
- IntSecurity.cs
- XmlCodeExporter.cs
- WithStatement.cs
- FileDetails.cs
- SqlDesignerDataSourceView.cs
- RuntimeConfigLKG.cs
- AbsoluteQuery.cs
- NetCodeGroup.cs
- SafeTimerHandle.cs
- KnownTypeHelper.cs
- WebReferencesBuildProvider.cs
- CompiledRegexRunnerFactory.cs
- AddIn.cs
- VersionedStreamOwner.cs
- Calendar.cs
- SimpleType.cs
- UrlRoutingModule.cs
- TokenBasedSet.cs
- InstanceDataCollection.cs
- QilTernary.cs
- RelatedPropertyManager.cs
- Compilation.cs
- VisualStyleTypesAndProperties.cs
- CallTemplateAction.cs
- Utils.cs
- JoinGraph.cs
- ValidationError.cs
- Model3D.cs
- ObjectCloneHelper.cs
- AuthenticateEventArgs.cs
- TransformerInfoCollection.cs
- CommandBindingCollection.cs
- ConfigurationProperty.cs
- NegatedCellConstant.cs
- EventProxy.cs
- AxHost.cs
- ScriptingScriptResourceHandlerSection.cs
- PhotoPrintingIntent.cs
- EntityStoreSchemaGenerator.cs
- BitmapData.cs
- DesignerSelectionListAdapter.cs
- AQNBuilder.cs
- LocalFileSettingsProvider.cs
- CustomErrorsSection.cs
- BasicHttpBindingCollectionElement.cs
- SqlUtils.cs
- FunctionQuery.cs
- ElementHostPropertyMap.cs
- Descriptor.cs
- HandlerFactoryWrapper.cs
- ObjectListItemCollection.cs
- Exceptions.cs
- XsltLoader.cs
- HTMLTextWriter.cs
- RegionData.cs
- VariantWrapper.cs
- IdentifierService.cs
- ComboBoxItem.cs
- XmlQueryRuntime.cs
- Compiler.cs
- TemplatePagerField.cs
- MemoryRecordBuffer.cs
- IdentityModelDictionary.cs
- ComponentConverter.cs
- ListViewItem.cs
- UrlAuthorizationModule.cs
- DynamicHyperLink.cs
- BatchParser.cs
- OwnerDrawPropertyBag.cs
- PatternMatcher.cs
- EventMappingSettings.cs
- PropertyEntry.cs
- SapiRecoInterop.cs
- Int16AnimationUsingKeyFrames.cs
- WSSecurityOneDotZeroReceiveSecurityHeader.cs
- HierarchicalDataBoundControlAdapter.cs
- StylusOverProperty.cs
- ContentWrapperAttribute.cs
- TransactionsSectionGroup.cs
- StorageConditionPropertyMapping.cs
- Decorator.cs
- AccessDataSourceView.cs
- ModelFunctionTypeElement.cs
- ScrollChrome.cs
- WebSysDisplayNameAttribute.cs
- BinaryCommonClasses.cs
- DeferredSelectedIndexReference.cs
- DataReceivedEventArgs.cs
- FileLevelControlBuilderAttribute.cs