Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • heba 1 post 21 karma points
    May 16, 2012 @ 15:33
    heba
    0

    error: "Cannot add a 'name' attribute to this collection as it does not exist in the schema"

    Hi All,

    Using Umbraco 5 MVC3 Project Template of visual studio, I have created a controller "Default1" 

    and created my model "Person" with the PersonSchema as bellow:

       public class Person : TypedEntity
        {
            public Person()
            {
                this.SetupFromSchema<PersonSchema>();
            }

            public string Name
            {
                get
                {
                    return this.Attributes["name"].DynamicValue;
                }
                set
                {
                    this.Attributes["name"].DynamicValue = value;
                }
            }
        }

        public class PersonSchema : EntitySchema
        {
            public PersonSchema()
            {
                this.Setup("person", "Person");
                this.SchemaType = "content";

                this.AttributeDefinitions.Add(new AttributeDefinition
                {
                    Id = new Umbraco.Framework.HiveId(Guid.Parse("{6DDE61B9-859F-4857-B02C-9E548BFBCB9D}")),
                    Name = "Name",
                    Alias = "name",
                    AttributeType = AttributeTypeRegistry.Current.GetAttributeType(StringAttributeType.AliasValue),
                    AttributeGroup = FixedGroupDefinitions.GeneralGroup,
                });
            }
        }

    The entity added successfully using the code below:

      public ActionResult Index()
            {
                var hive = RoutableRequestContext.Application.Hive.GetAllReadWriteProviders().FirstOrDefault();

                var hWriter = RoutableRequestContext.Application.Hive.GetWriter<IContentStore>(new Uri("content://"));

                using (var uow = hWriter.Create())
                {
                    Person person = new Person()
                    {
                        Name = "Test"
                    };

                    uow.Repositories.AddOrUpdate(person);

                    uow.Complete();
                }

                return View();
            }

    but when I'm trying to retrieve this attribute I got the following error :

    "Cannot add a 'name' attribute to this collection as it does not exist in the schema"

    this is my code:

         public ActionResult Get()
            {
                var hReader = RoutableRequestContext.Application.Hive.GetReader<IContentStore>();

                using (var t = hReader.CreateReadonly())
                {
                    var persons = t.Repositories.GetAll<Person>();
                }

                return View();
            }

     

    Please advice

Please Sign in or register to post replies

Write your reply to:

Draft