示例#1
0
        public T CreateItemDetached <T>(string entityTypeName)
            where T : class, IDerivedEntity
        {
            //if (!this.entitySets.ContainsKey(entityTypeName))
            //{
            //    this.InitializeDataSet(entityTypeName);
            //}
            //var entityType = Type.GetType(this.metadataSrv.Namespace + "." + entityTypeName);
            //var entity = Activator.CreateInstance(entityType);

            var entityType = this.metadataSrv.EntityTypes[entityTypeName];
            var dto        = new Dto();

            dto.SetDefaultValues(entityType);
            var entity            = new Entity(entityTypeName, dto);
            var derivedEntityType = Type.GetType(this.metadataSrv.Namespace + "." + entityTypeName);
            var derivedEntity     = (T)Activator.CreateInstance(derivedEntityType, new object[] { entity });

            return(derivedEntity);
        }