Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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
is working on a reply...