Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't insert #124

Open
LestatDelionkur opened this issue Jan 31, 2018 · 5 comments
Open

Can't insert #124

LestatDelionkur opened this issue Jan 31, 2018 · 5 comments

Comments

@LestatDelionkur
Copy link

LestatDelionkur commented Jan 31, 2018

I'm insert tuple with the following code
var result= await _primaryIndex.Insert<TarantoolTuple<T>>(TarantoolTuple.Create(entity));
and get an exception "Тarantool returns an error for request with id: 87, code: 0x00008027 and message: Tuple field count 1 is less than required by a defined index (expected 2)."
This is my entity code:

    [MsgPackArray]
    public class UnitType
    {
        [MsgPackArrayElement(0)]
        public ulong Id { get; set; }
        [MsgPackArrayElement(1)]
        public string Name { get; set; }
    }

  --Space definition
    unit_type=box.schema.space.create('unit_type',{format={
        [1]={["name"]="id",["type"]="unsigned"},
        [2]={["name"]="name",["type"]="string"}
    },if_not_exists = true})
    unit_type_id_seq=box.schema.sequence.create('unit_type_id_seq');

    unit_type:create_index('primary',{
        if_not_exists=true,
        type='TREE',
        unique=true,
        parts={1,'UNSIGNED'}
        ,sequence='unit_type_id_seq'
    })

Can you help me with insert and update operations? I can't find guide for this

@aensidhe
Copy link
Member

aensidhe commented Jan 31, 2018

So, usually, when you have sequence, you want id be equals to nil. Also you do not (for insert) need to wrap your entity in tuple. I would suggest to try this: var result= await _primaryIndex.Insert(entity);.

I will look into this tomorrow, if advice will not help.

@LestatDelionkur
Copy link
Author

Thanks! It's works great. One more question) If i use array field in tarantool, does connector map it to the class property with type ulong[]?

@aensidhe
Copy link
Member

aensidhe commented Feb 5, 2018

@LestatDelionkur yes, if every member of array is assignable to ulong.

@LestatDelionkur
Copy link
Author

Hi. I always get this error "ConverterNotFoundException: Converter not found for type User ProGaudi.MsgPack.Light.MsgPackContext.GetConverter()" . Can you help me again?)

    [MsgPackArray]
    [Space("user")]
    public class User : IDbEntity
    {
        [MsgPackArrayElement(0)]
        public ulong? Id { get; set; }
        [MsgPackArrayElement(1)]
        public string Login { get; set; }
        [MsgPackArrayElement(2)]
        public string Username { get; set; }
        [MsgPackArrayElement(3)]
        public string PasswordHash { get; set; }
        [MsgPackArrayElement(4)]
        public ulong? StatusId { get; set; }
        [MsgPackArrayElement(5)]
        public ulong[] Roles { get; set; }
        [MsgPackArrayElement(6)]
        public string Email { get; set; }
        [MsgPackArrayElement(7)]
        public bool EmailConfirmed { get; set; }
        [MsgPackArrayElement(8)]
        public string Phone { get; set; }
        [MsgPackArrayElement(9)]
        public bool PhoneNumberConfirmed { get; set; }
        [MsgPackArrayElement(10)]
        public bool TwoFactorEnabled { get; set; }
        [MsgPackArrayElement(11)]
        public int AccessFailedCount { get; set; }

    }
  user=box.schema.space.create('user',{format={
        [1]={["name"]="id",["type"]="unsigned"},
        [2]={["name"]="login",["type"]="string"},
        [3]={["name"]="username",["type"]="string"},
        [4]={["name"]="password",["type"]="string"},
        [5]={["name"]="status_id",["type"]="unsigned"},
        [6]={["name"]="roles",["type"]="array"},
        [7]={["name"]="email",["type"]="string"},
        [8]={["name"]="email_confirmed",["type"]="boolean"} ,
        [9]={["name"]="phone",["type"]="string"},
        [10]={["name"]="phone_number_confirmed",["type"]="boolean"},
        [11]={["name"]="two_factor_enabled",["type"]="boolean"},
        [12]={["name"]="access_failed_count",["type"]="integer"}      
    }})

@aensidhe
Copy link
Member

When you create a Box object, you have an option to pass a MsgPackContext for it. You should do something like this:

var msgPackContext = new MsgPackContext();

// this will trigger scan of your assembly for classes, marked with attributes.
msgPackContext.DiscoverConverters<User >();

var clientOptions = new ClientOptions(options.Value.ReplicationSource, context: context);
this.Box = new Box(clientOptions);
this.Box.Connect().GetAwaiter().GetResult();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants