Orchard data insert/delete for non content item

孤街浪徒 提交于 2019-12-01 00:44:05
Behnam Esmaili

If you mean "creating a table without ContentPart" by non-content, then just create your desired model in the models folder :

  public class MyRecord{

        public virtual int Id { get; set; }

        public virtual string FOO{ get; set; }

        public virtual string BAR{ get; set; }

    }

and obviously you must create a table in migration as following :

SchemaBuilder.CreateTable("MyRecord",
                table => table
                    .Column<int>("Id", c => c.PrimaryKey().Identity())
                    .Column<string>("FOO")
                    .Column<string>("BAR")
                ); 

and finally where you want to have a transaction over table ,simply inject an instance of your model's repository :

private readonly IRepository<MyRecord> _repository;

public SomeClass(IRepository<MyRecord> repository){
    _repository = repository;    
}


  public SomeMethod(){
        var record = new MyRecord();
        //initialize your class here
      _repository.Create(record);
  }

Important to note is that your record class must be in the Models folder and must contain an Id property.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!