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


C# EntitySet.AddEntity方法代码示例

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


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

示例1: SetUp

        public void SetUp()
        {
            entity1 = new EntityImpl("Entity1");
            entity2 = new EntityImpl("Entity2");

            entitySet = new EntitySetImpl();
            entitySet.AddEntity(entity1);
            entitySet.AddEntity(entity2);
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:9,代码来源:Specs_For_Entities.cs

示例2: SetUp

        public void SetUp()
        {
            entity1 = new EntityImpl("Entity1");
            entity2 = new EntityImpl("Entity2");

            entitySet = new EntitySetImpl();
            entitySet.AddEntity(entity1);
            entitySet.AddEntity(entity2);

            entity1.CreateReferenceTo(entity2);
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:11,代码来源:Specs_For_Entities.cs

示例3: CreateEntity

        private static Entity CreateEntity(EntitySet set, string entityName)
        {
            var entity = new EntityImpl(entityName);
            entity.AddProperty(new PropertyImpl("Property1"));
            entity.AddProperty(new PropertyImpl("Property2"));
            entity.AddProperty(new PropertyImpl("Property3"));

            set.AddEntity(entity);

            return entity;
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:11,代码来源:ModelSetup.cs

示例4: Setup

        public void Setup()
        {
            // Setup Database
            database = new Database("DB1");
            var table = new Table("User");
            table.AddColumn(new Column("Name"));
            table.AddColumn(new Column("AddressStreet"));
            table.AddColumn(new Column("AddressCity"));
            table.AddColumn(new Column("AddressCountry"));
            database.AddTable(table);

            // Setup Entities
            entitySet = new EntitySetImpl();
            Entity userEntity = new EntityImpl("User");
            userEntity.AddProperty(new PropertyImpl("Name"));

            // Create the Address type
            spec = new ComponentSpecificationImpl("Address");

            spec.AddProperty(new ComponentPropertyImpl("Street"));
            spec.AddProperty(new ComponentPropertyImpl("City"));
            spec.AddProperty(new ComponentPropertyImpl("Country"));

            // Create the Address component for the User entity.
            component = spec.CreateImplementedComponentFor(userEntity, "HomeAddress");

            entitySet.AddEntity(userEntity);
            entitySet.AddComponentSpecification(spec);

            // Setup the Mappings
            mappingSet = new MappingSetImpl(database, entitySet);
            componentMapping = new ComponentMappingImpl();
            mappingSet.AddMapping(componentMapping);

            componentMapping.AddPropertyAndColumn(component.Properties[0], table.Columns[1]);
            componentMapping.AddPropertyAndColumn(component.Properties[1], table.Columns[2]);
            componentMapping.AddPropertyAndColumn(component.Properties[2], table.Columns[3]);

            // Add the mapping between the Name property and the Name column in the database table.
            mappingSet.ChangeMappedColumnFor(userEntity.ConcreteProperties[0]).To(table.Columns[0]);
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:41,代码来源:Specs_For_Components.cs

示例5: LoadSheetData

        private static EntitySet LoadSheetData(string file, string sheetname, Type type)
        {
            string connstr = string.Format(TemplateImport, file);
            EntityMappings mapping = type.GetMappedFields();
            EntitySet rlt = new EntitySet();
            using (OleDbConnection cn = new OleDbConnection(connstr))
            {
                try
                {
                    using (OleDbCommand cmd = cn.CreateCommand())
                    {
                        cn.Open();
                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.CommandText = string.Format(SelectScriptTemplate, sheetname);
                        using (OleDbDataReader r = cmd.ExecuteReader())
                        {
                            int row = 0;
                            List<string> columns = new List<string>();
                            while (r.Read())
                            {
                                row++;
                                Entity o = Activator.CreateInstance(type) as Entity;
                                if (o != null)
                                {
                                    for (int i = 0; i < r.VisibleFieldCount; i++)
                                    {
                                        //string n = r.GetName(i);
                                        if (row == 1)
                                        {
                                            object colobj = r.GetValue(i);
                                            columns.Add(colobj.ToString());
                                        }
                                        else
                                        {
                                            string n = columns[i];
                                            if (!string.IsNullOrEmpty(n))
                                            {
                                                n = n.Replace("/", "");
                                                n = n.Replace("\\", "");
                                                if (mapping.ContainsKey(n))
                                                {
                                                    EntityMappingsItem item = mapping[n];
                                                    FieldInfo info = item.FieldInfo;
                                                    object value = r.GetValue(i);
                                                    o.OriginalValues[n] = value;
                                                    //info.SetValue(o, value);
                                                }
                                            }
                                        }
                                    }
                                    if (row > 1)
                                    {
                                        if (!o.IsPFieldEmpty)
                                        {
                                            o._MiscInfo = string.Format("File: {0}, Sheet:{1}, Line:{2}", file, sheetname, row);
                                            rlt.AddEntity(o);
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    cn.Close();
                }

            }
            return rlt;
        }
开发者ID:mind0n,项目名称:hive,代码行数:74,代码来源:IpAt.cs

示例6: ProcessSubclasses

        private void ProcessSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity parentEntity, IEnumerable<subclass> subclasses, string schemaName, string tableName, ParseResults parseResults, string unqualifiedNamespace)
        {
            if (subclasses == null) return;

            foreach (subclass hSubclass in subclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);

                #region Discriminator
                if (!string.IsNullOrWhiteSpace(hSubclass.discriminatorvalue))
                {
                    childEntity.DiscriminatorValue = hSubclass.discriminatorvalue;

                    //ArchAngel.Providers.EntityModel.Model.EntityLayer.Discriminator d = new Discriminator()
                    //{
                    //    AllowNull = xx,
                    //    ColumnName = hSubclass.d,
                    //    DiscriminatorType = xx,
                    //    Force = xx,
                    //    Formula = xx,
                    //    Insert = xx
                    //};
                    //throw new NotImplementedException("TODO: fixup discriminator stuff");
                    //Grouping g = new AndGrouping();
                    //IColumn column = parentEntity.Discriminator.RootGrouping.Conditions[0].Column;
                    //ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator op = ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator.Equal;
                    //ExpressionValue value = new ExpressionValueImpl(hSubclass.discriminatorvalue);

                    //if (column != null && op != null && value != null)
                    //    g.AddCondition(new ConditionImpl(column, op, value));

                    //if (childEntity.Discriminator == null)
                    //    childEntity.Discriminator = new DiscriminatorImpl();

                    //childEntity.Discriminator.RootGrouping = g;
                }
                #endregion

                parentEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();

                childTableMapping.FromTable = database.GetTable(tableName, schemaName);
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, parseResults, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessSubclasses(mappingSet, database, entities, childEntity, hSubclass.subclass1, schemaName, tableName, parseResults, unqualifiedNamespace);
            }
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:74,代码来源:EntityLoader.cs

示例7: ProcessUnionSubclasses

        private void ProcessUnionSubclasses(object parent, MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<unionsubclass> unionsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (unionsubclasses == null) return;

            @class hClass = null;
            unionsubclass parentSubClass = null;

            if (parent is @class)
                hClass = (@class)parent;
            else
                parentSubClass = (unionsubclass)parent;

            foreach (unionsubclass hSubclass in unionsubclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                childTableMapping.FromTable = database.GetTable(hSubclass.table.UnBackTick(), hSubclass.schema.UnBackTick());
                childTableMapping.ToEntity = childEntity;

                foreach (var ip in childEntity.InheritedProperties)
                {
                    PropertyImpl np = new PropertyImpl(ip);
                    np.IsHiddenByAbstractParent = true;
                    childEntity.AddProperty(np);
                    string columnName = "";
                    var props = hClass.Properties().ToList();

                    if (hClass != null)
                    {
                        property matchingProp = hClass.Properties().SingleOrDefault(p => p.name == ip.Name);

                        if (matchingProp != null)
                        {
                            if (matchingProp.column != null)
                                columnName = matchingProp.column;
                            else if (matchingProp.Columns().Count > 0)
                                columnName = matchingProp.Columns()[0].name;
                        }
                        else
                        {
                            if (hClass.Id().column1 != null)
                                columnName = hClass.Id().column1;
                            else if (hClass.Id().column != null && hClass.Id().column.Count() > 0)
                                columnName = hClass.Id().column[0].name;
                        }
                    }
                    else
                        columnName = parentSubClass.Properties().Single(p => p.name == ip.Name).column;

                    IColumn column = childTableMapping.FromTable.GetColumn(columnName.UnBackTick());

                    if (column != null)
                        childTableMapping.AddPropertyAndColumn(np, column);
                }

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                // Add the parent's key properties as hidden properties
                foreach (var keyProp in newEntity.Key.Properties)
                {
                    Property childP = childEntity.PropertiesHiddenByAbstractParent.SingleOrDefault(p => p.Name == keyProp.Name);

                    if (childP != null)
                    {
                        //childP.IsHiddenByAbstractParent = true;
                        childP.IsKeyProperty = true;
                    }
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessUnionSubclasses(hSubclass, mappingSet, database, entities, childEntity, hSubclass.unionsubclass1, results, unqualifiedNamespace);
            }
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:97,代码来源:EntityLoader.cs

示例8: ProcessJoinedSubclasses

        private void ProcessJoinedSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<joinedsubclass> joinedsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (joinedsubclasses == null) return;

            ITable parentTable = null;

            if (newEntity.MappedTables().Count() > 0)
                parentTable = newEntity.MappedTables().ElementAt(0);

            foreach (joinedsubclass hSubclass in joinedsubclasses)
            {
                Entity childEntity;
                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);

                    unqualifiedNamespace = @namespace;
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                ITable subClassTable;

                if (!string.IsNullOrEmpty(hSubclass.table))
                {
                    string schema = "";

                    if (!string.IsNullOrEmpty(hSubclass.schema))
                        schema = hSubclass.schema;
                    else if (parentTable != null)
                        schema = parentTable.Schema;

                    subClassTable = database.GetTable(hSubclass.table.UnBackTick(), schema.UnBackTick());
                    subClassTable.Database = database;
                }
                else
                    subClassTable = parentTable;

                childTableMapping.FromTable = subClassTable;
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                if (hSubclass.key != null)
                {
                    string keyColumnName;

                    if (!string.IsNullOrEmpty(hSubclass.key.column1))
                        keyColumnName = hSubclass.key.column1;
                    else //if (hSubclass.key.column != null && hSubclass.key.column.Count() > 0)
                        keyColumnName = hSubclass.key.column[0].name;

                    Property keyProp = childEntity.Properties.FirstOrDefault(p => p.MappedColumn() != null && p.MappedColumn().Name == keyColumnName);

                    if (keyProp == null)
                    {
                        keyProp = CreateProperty(childEntity, childTableMapping, hSubclass.key, subClassTable);
                        SetPropertyInfoFromParsedCode(keyProp, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, childEntity.Name);
                        keyProp.IsHiddenByAbstractParent = true;
                    }
                    keyProp.IsKeyProperty = true;
                }
                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessJoinedSubclasses(mappingSet, database, entities, childEntity, hSubclass.joinedsubclass1, results, unqualifiedNamespace);
            }
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:83,代码来源:EntityLoader.cs

示例9: SetUp

        public void SetUp()
        {
            entities = new EntitySetImpl();

            entity1 = new EntityImpl("Entity1");
            entity1.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true });
            entity1.AddProperty(new PropertyImpl("Property") { Type = "bool" });

            entity2 = new EntityImpl("Entity2");
            entity2.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true });

            entities.AddEntity(entity1);
            entities.AddEntity(entity2);

            reference = entity1.CreateReferenceTo(entity2);
            reference.Cardinality1 = Cardinality.One;
            reference.Cardinality2 = Cardinality.One;
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:18,代码来源:Specs_For_Creating_Tables_From_Entities.cs


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