当前位置: 首页>>代码示例>>C#>>正文


C# MetadataWorkspace.LoadFromAssembly方法代码示例

本文整理汇总了C#中MetadataWorkspace.LoadFromAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataWorkspace.LoadFromAssembly方法的具体用法?C# MetadataWorkspace.LoadFromAssembly怎么用?C# MetadataWorkspace.LoadFromAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MetadataWorkspace的用法示例。


在下文中一共展示了MetadataWorkspace.LoadFromAssembly方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

        /// <summary>
        /// Generates metadata for given item collection.
        /// Fetches CLR models from given assembly.
        /// </summary>
        /// <param name="metadataWorkspace">The metadata workspace.</param>
        /// <param name="modelAssembly">The model assembly.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <returns></returns>
        public static Metadata Generate(MetadataWorkspace metadataWorkspace, Assembly modelAssembly, string connectionString) {
            metadataWorkspace.RegisterItemCollection(new ObjectItemCollection());
            metadataWorkspace.LoadFromAssembly(modelAssembly);

            var itemCollection = metadataWorkspace.GetItemCollection(DataSpace.CSpace);
            var objectItemCollection = (ObjectItemCollection)metadataWorkspace.GetItemCollection(DataSpace.OSpace);

            return Generate(metadataWorkspace, itemCollection, objectItemCollection, modelAssembly, connectionString);
        }
开发者ID:amartelr,项目名称:Beetle.js,代码行数:17,代码来源:MetadataGenerator.cs

示例2: InitializeMetadataWorkspace

 public static void InitializeMetadataWorkspace(TestContext testContext)
 {
     StringReader sr = new StringReader(testCsdl);
     XmlReader reader = XmlReader.Create(sr);
     metadataWorkspace = new MetadataWorkspace();
     EdmItemCollection edmItemCollection = new EdmItemCollection(new XmlReader[] { reader });
     metadataWorkspace.RegisterItemCollection(edmItemCollection);
     metadataWorkspace.RegisterItemCollection(new ObjectItemCollection());
     metadataWorkspace.LoadFromAssembly(Assembly.GetExecutingAssembly());            
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:10,代码来源:ObjectContextMetadataTests.cs

示例3: GetEdmType

        /// <summary>
        /// Retrieves the <see cref="StructuralType"/> corresponding to the given CLR type (where the
        /// type is an entity or complex type).
        /// </summary>
        /// <remarks>
        /// If no mapping exists for <paramref name="clrType"/>, but one does exist for one of its base 
        /// types, we will return the mapping for the base type.
        /// </remarks>
        /// <param name="workspace">The <see cref="MetadataWorkspace"/></param>
        /// <param name="clrType">The CLR type</param>
        /// <returns>The <see cref="StructuralType"/> corresponding to that CLR type, or <c>null</c> if the Type
        /// is not mapped.</returns>
        public static StructuralType GetEdmType(MetadataWorkspace workspace, Type clrType)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException("workspace");
            }
            if (clrType == null)
            {
                throw new ArgumentNullException("clrType");
            }

            if (clrType.IsPrimitive || clrType == typeof(object))
            {
                // want to avoid loading searching system assemblies for
                // types we know aren't entity or complex types
                return null;
            }

            // We first locate the EdmType in "OSpace", which matches the name and namespace of the CLR type
            EdmType edmType = null;
            do
            {
                if (!workspace.TryGetType(clrType.Name, clrType.Namespace, DataSpace.OSpace, out edmType))
                {
                    // If EF could not find this type, it could be because it is not loaded into
                    // its current workspace.  In this case, we explicitly load the assembly containing 
                    // the CLR type and try again.
                    workspace.LoadFromAssembly(clrType.Assembly);
                    workspace.TryGetType(clrType.Name, clrType.Namespace, DataSpace.OSpace, out edmType);
                }
            }
            while (edmType == null && (clrType = clrType.BaseType) != typeof(object) && clrType != null);

            // Next we locate the StructuralType from the EdmType.
            // This 2-step process is necessary when the types CLR namespace does not match Edm namespace.
            // Look at the EdmEntityTypeAttribute on the generated entity classes to see this Edm namespace.
            StructuralType structuralType = null;
            if (edmType != null &&
                (edmType.BuiltInTypeKind == BuiltInTypeKind.EntityType || edmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType))
            {
                workspace.TryGetEdmSpaceType((StructuralType)edmType, out structuralType);
            }

            return structuralType;
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:57,代码来源:ObjectContextUtilities.cs

示例4: O_space_types_are_discovered_when_using_attribute_based_mapping

        public void O_space_types_are_discovered_when_using_attribute_based_mapping()
        {
            var edmItemCollection = new EdmItemCollection(
                new[]
                    {
                        XDocument.Load(
                            typeof(AttributeBasedOCLoading).Assembly.GetManifestResourceStream(
                                "System.Data.Entity.TestModels.TemplateModels.Schemas.MonsterModel.csdl")).CreateReader()
                    });

            var storeItemCollection = new StoreItemCollection(
                new[]
                    {
                        XDocument.Load(
                            typeof(AttributeBasedOCLoading).Assembly.GetManifestResourceStream(
                                "System.Data.Entity.TestModels.TemplateModels.Schemas.MonsterModel.ssdl")).CreateReader()
                    });
            var storageMappingItemCollection = LoadMsl(
                edmItemCollection, storeItemCollection, XDocument.Load(
                    typeof(AttributeBasedOCLoading).Assembly.GetManifestResourceStream(
                        "System.Data.Entity.TestModels.TemplateModels.Schemas.MonsterModel.msl")));

            var workspace = new MetadataWorkspace(
                () => edmItemCollection,
                () => storeItemCollection,
                () => storageMappingItemCollection);

            var assembly = BuildEntitiesAssembly(ObjectLayer);
            workspace.LoadFromAssembly(assembly);

            var oSpaceItems = (ObjectItemCollection)workspace.GetItemCollection(DataSpace.OSpace);

            // Sanity checks that types/relationships were actually found
            // Entity types
            var entityTypes = oSpaceItems
                .OfType<EdmType>()
                .Where(i => i.BuiltInTypeKind == BuiltInTypeKind.EntityType)
                .ToList();

            Assert.Equal(
                new[]
                    {
                        "BackOrderLine2Mm", "BackOrderLineMm", "BarcodeDetailMm", "BarcodeMm", "ComplaintMm", "ComputerDetailMm",
                        "ComputerMm", "CustomerInfoMm", "CustomerMm", "DiscontinuedProductMm", "DriverMm", "IncorrectScanMm",
                        "LastLoginMm", "LicenseMm", "LoginMm", "MessageMm", "OrderLineMm", "OrderMm", "OrderNoteMm",
                        "OrderQualityCheckMm", "PageViewMm", "PasswordResetMm", "ProductDetailMm", "ProductMm", "ProductPageViewMm",
                        "ProductPhotoMm", "ProductReviewMm", "ProductWebFeatureMm", "ResolutionMm", "RSATokenMm", "SmartCardMm",
                        "SupplierInfoMm", "SupplierLogoMm", "SupplierMm", "SuspiciousActivityMm"
                    },
                entityTypes.Select(i => i.Name).OrderBy(n => n));

            Assert.True(entityTypes.All(e => e.NamespaceName == "BuildMonsterModel"));
            Assert.True(entityTypes.All(e => oSpaceItems.GetClrType((StructuralType)e).Assembly == assembly));

            // Complex types
            var complexTypes = oSpaceItems
                .OfType<EdmType>()
                .Where(i => i.BuiltInTypeKind == BuiltInTypeKind.ComplexType)
                .ToList();

            Assert.Equal(
                new[] { "AuditInfoMm", "ConcurrencyInfoMm", "ContactDetailsMm", "DimensionsMm", "PhoneMm" },
                complexTypes.Select(i => i.Name).OrderBy(n => n));

            Assert.True(complexTypes.All(e => e.NamespaceName == "BuildMonsterModel"));
            Assert.True(complexTypes.All(e => oSpaceItems.GetClrType((StructuralType)e).Assembly == assembly));

            // Enum types
            var enumTypes = oSpaceItems
                .OfType<EdmType>()
                .Where(i => i.BuiltInTypeKind == BuiltInTypeKind.EnumType)
                .ToList();

            Assert.Equal(
                new[] { "LicenseStateMm", "PhoneTypeMm" },
                enumTypes.Select(i => i.Name).OrderBy(n => n));

            Assert.True(enumTypes.All(e => e.NamespaceName == "BuildMonsterModel"));
            Assert.True(enumTypes.All(e => oSpaceItems.GetClrType((EnumType)e).Assembly == assembly));

            // Associations
            var associations = oSpaceItems
                .OfType<AssociationType>()
                .Where(i => i.BuiltInTypeKind == BuiltInTypeKind.AssociationType)
                .ToList();

            Assert.Equal(
                new[]
                    {
                        "Barcode_BarcodeDetail", "Barcode_IncorrectScanActual", "Barcode_IncorrectScanExpected", "Complaint_Resolution",
                        "Computer_ComputerDetail", "Customer_Complaints", "Customer_CustomerInfo", "Customer_Logins", "Customer_Orders",
                        "DiscontinuedProduct_Replacement", "Driver_License", "Husband_Wife", "LastLogin_SmartCard", "Login_LastLogin",
                        "Login_Orders", "Login_PageViews", "Login_PasswordResets", "Login_ReceivedMessages", "Login_RSAToken",
                        "Login_SentMessages", "Login_SmartCard", "Login_SuspiciousActivity", "Order_OrderLines", "Order_OrderNotes",
                        "Order_QualityCheck", "Product_Barcodes", "Product_OrderLines", "Product_ProductDetail", "Product_ProductPageViews",
                        "Product_ProductPhoto", "Product_ProductReview", "Products_Suppliers", "ProductWebFeature_ProductPhoto",
                        "ProductWebFeature_ProductReview", "Supplier_BackOrderLines", "Supplier_SupplierInfo", "Supplier_SupplierLogo"
                    },
                associations.Select(i => i.Name).OrderBy(n => n));

//.........这里部分代码省略.........
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:101,代码来源:AttributeBasedOCLoading.cs

示例5: LoadAssemblyIntoWorkspace

 private static void LoadAssemblyIntoWorkspace(MetadataWorkspace workspace, Assembly assembly)
 {
     workspace.LoadFromAssembly(assembly);
 }
开发者ID:mbsky,项目名称:myextensions,代码行数:4,代码来源:EntityHelper.cs

示例6: SetEntityConnection

        private bool SetEntityConnection(List<string> metadataPaths, EntityConnectionStringBuilder connStrBuilder)
        {
            // It's possible the metadata was specified in the original connection string, but we filtered out everything due to not being able to resolve it to anything.
            // In that case, warnings have already been displayed to indicate which paths were removed, so no need to display another message.            
            if (metadataPaths.Count > 0)
            {
                try
                {
                    // Get the connection first, because it might be needed to gather provider services information
                    DbConnection dbConnection = GetDbConnection(connStrBuilder);

                    MetadataWorkspace metadataWorkspace = new MetadataWorkspace(metadataPaths, _assemblies);

                    // Ensure that we have all of the item collections registered. If some of them are missing this will cause problems eventually if we need to 
                    // execute a query to get detailed schema information, but that will be handled later. For now just register everything to prevent errors in the 
                    // stack that would not be understood by the user in the designer at this point.
                    ItemCollection edmItemCollection;
                    ItemCollection storeItemCollection;
                    ItemCollection csItemCollection;
                    if (!metadataWorkspace.TryGetItemCollection(DataSpace.CSpace, out edmItemCollection))
                    {
                        edmItemCollection = new EdmItemCollection();
                        metadataWorkspace.RegisterItemCollection(edmItemCollection);
                    }

                    if (!metadataWorkspace.TryGetItemCollection(DataSpace.SSpace, out storeItemCollection))
                    {
                        return false;
                    }

                    if (!metadataWorkspace.TryGetItemCollection(DataSpace.CSSpace, out csItemCollection))
                    {
                        Debug.Assert(edmItemCollection != null && storeItemCollection != null, "edm and store ItemCollection should be populated already");
                        metadataWorkspace.RegisterItemCollection(new StorageMappingItemCollection(edmItemCollection as EdmItemCollection, storeItemCollection as StoreItemCollection));
                    }
                    
                    // Create an ObjectItemCollection beforehand so that we can load objects by-convention
                    metadataWorkspace.RegisterItemCollection(new ObjectItemCollection());

                    // Load OSpace metadata from all of the assemblies we know about
                    foreach (Assembly assembly in _assemblies)
                    {
                        metadataWorkspace.LoadFromAssembly(assembly);
                    }
                    
                    if (dbConnection != null)
                    {
                        _entityConnection = new EntityConnection(metadataWorkspace, dbConnection);
                        return true;
                    }
                    // else the DbConnection could not be created and the error should have already been displayed
                }
                catch (Exception ex)
                {   
                    StringBuilder exceptionMessage = new StringBuilder();
                    exceptionMessage.AppendLine(Strings.Error_MetadataLoadError);
                    exceptionMessage.AppendLine();
                    exceptionMessage.Append(ex.Message);
                    ShowError(exceptionMessage.ToString());
                }
            }

            return false;
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:64,代码来源:EntityDataSourceDesignerHelper.cs

示例7: GetCSpacetype

        public static EntityType GetCSpacetype(Type currentType, MetadataWorkspace mdw)
        {
            mdw.LoadFromAssembly(currentType.Assembly);

            EntityType ospaceEntityType = null;
            StructuralType cspaceEntityType = null;
            if (mdw.TryGetItem<EntityType>(
                currentType.FullName, DataSpace.OSpace, out ospaceEntityType))
            {
                if (mdw.TryGetEdmSpaceType(ospaceEntityType,
                    out cspaceEntityType))
                    return cspaceEntityType as EntityType;
            }

            return null;
        }
开发者ID:BostonSymphOrch,项目名称:HENRY-archives,代码行数:16,代码来源:BusinessObjectHelper.cs

示例8: LoadFromAssembly_checks_only_given_assembly_for_views

            public void LoadFromAssembly_checks_only_given_assembly_for_views()
            {
                var mockCache = new Mock<IViewAssemblyCache>();
                var workspace = new MetadataWorkspace(
                    () => new EdmItemCollection(Enumerable.Empty<XmlReader>()),
                    () => null,
                    () => null,
                    () => new ObjectItemCollection(mockCache.Object));

                workspace.LoadFromAssembly(typeof(object).Assembly);

                mockCache.Verify(m => m.CheckAssembly(typeof(object).Assembly, false), Times.Once());
            }
开发者ID:christiandpena,项目名称:entityframework,代码行数:13,代码来源:MetadataWorkspaceTests.cs


注:本文中的MetadataWorkspace.LoadFromAssembly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。