internal static DatabaseMapping ReadDatabaseMapping(XmlReader reader) { System.Diagnostics.Debug.Assert(reader.NodeType == XmlNodeType.Element); if(!IsInNamespace(reader) || reader.LocalName != XmlMappingConstant.Database) { return null; } ValidateAttributes(reader, new[] { XmlMappingConstant.Name, XmlMappingConstant.Provider }); DatabaseMapping dm = new DatabaseMapping(); dm.DatabaseName = RequiredAttribute(reader, XmlMappingConstant.Name); dm.Provider = OptionalAttribute(reader, XmlMappingConstant.Provider); if(!reader.IsEmptyElement) { reader.ReadStartElement(); reader.MoveToContent(); while(reader.NodeType != XmlNodeType.EndElement) { if(reader.NodeType == XmlNodeType.Whitespace || !IsInNamespace(reader)) { reader.Skip(); continue; } switch(reader.LocalName) { case XmlMappingConstant.Table: dm.Tables.Add(ReadTableMapping(reader)); break; case XmlMappingConstant.Function: dm.Functions.Add(ReadFunctionMapping(reader)); break; default: throw Error.UnrecognizedElement(String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}{1}{2}", reader.Prefix, String.IsNullOrEmpty(reader.Prefix) ? "" : "/", reader.LocalName)); } reader.MoveToContent(); } if(reader.LocalName != XmlMappingConstant.Database) { throw Error.UnexpectedElement(XmlMappingConstant.Database, String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}{1}{2}", reader.Prefix, String.IsNullOrEmpty(reader.Prefix) ? "" : "/", reader.LocalName)); } reader.ReadEndElement(); } else { System.Diagnostics.Debug.Assert(false, "DatabaseMapping has no content"); reader.Skip(); } return dm; }
[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // FindType method call. internal MappedMetaModel(MappingSource mappingSource, Type contextType, DatabaseMapping mapping) { this.mappingSource = mappingSource; this.contextType = contextType; this.mapping = mapping; this.modules = new HashSet<Module>(); this.modules.Add(this.contextType.Module); this.metaTypes = new Dictionary<Type, MetaType>(); this.metaTables = new Dictionary<Type, MetaTable>(); this.types = new Dictionary<string, Type>(); // Provider type if (this.providerType == null && !String.IsNullOrEmpty(this.mapping.Provider)) { this.providerType = this.FindType(this.mapping.Provider, typeof(SqlProvider).Namespace); if (this.providerType == null) { throw Error.ProviderTypeNotFound(this.mapping.Provider); } } else if (this.providerType == null) { this.providerType = typeof(SqlProvider); } this.Init(); }
[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // FindType method call. internal MappedMetaModel(MappingSource mappingSource, Type contextType, DatabaseMapping mapping) { this.mappingSource = mappingSource; this.contextType = contextType; this.mapping = mapping; this.modules = new HashSet<Module>(); this.modules.Add(this.contextType.Module); this.metaTypes = new Dictionary<Type, MetaType>(); this.metaTables = new Dictionary<Type, MetaTable>(); this.types = new Dictionary<string, Type>(); #warning [FB] REFACTOR SQL Server specific. Requires change to have its provider type injected instead of it tries to discover it on its own using sql server's specific namespace. // Provider type if (this.providerType == null && !String.IsNullOrEmpty(this.mapping.Provider)) { this.providerType = this.FindType(this.mapping.Provider, typeof(System.Data.Linq.DbEngines.SqlServer.SqlProvider).Namespace); if (this.providerType == null) { throw Error.ProviderTypeNotFound(this.mapping.Provider); } } else if (this.providerType == null) { this.providerType = typeof(System.Data.Linq.DbEngines.SqlServer.SqlProvider); } this.Init(); }
[ResourceExposure(ResourceScope.Assembly)] // map parameter contains type names. private XmlMappingSource(DatabaseMapping map) { this.map = map; }