Click here to Skip to main content
14,539,550 members
   

C#

 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 11:23
MemberExoskeletor8-Mar-20 11:23 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 13:28
professionalMycroft Holmes8-Mar-20 13:28 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 14:20
MemberExoskeletor8-Mar-20 14:20 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 14:51
professionalMycroft Holmes8-Mar-20 14:51 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 14:54
MemberExoskeletor8-Mar-20 14:54 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 14:56
MemberExoskeletor8-Mar-20 14:56 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 15:12
professionalMycroft Holmes8-Mar-20 15:12 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 16:02
MemberExoskeletor8-Mar-20 16:02 
i prefer to know if all of them are identical, sequence is important when the app is running ,im getting them in the sequence i want with this code:

 public static int GetSequenceHashCode<T>(this IList<T> sequence)
        {
            const int seed = 487;
            const int modifier = 31;

            unchecked
            {
                return sequence.Aggregate(seed, (current, item) =>
                    (current * modifier) + item.GetHashCode());
            }
        }
public static void AddTemplate(int category, List<int> images)
        {
var tmpl = new Template()
            {
                Category = category,
            };
            var img1 = new TemplateImage()
            {
                Category = category,
                Image = images[0],
            };
            var img2 = new TemplateImage()
            {
                Category = category,
                Image = images[1],
            };
            var img3 = new TemplateImage()
            {
                Category = category,
                Image = images[2],
            };
            var img4 = new TemplateImage()
            {
                Category = category,
                Image = images[3],
            };
            var img5 = new TemplateImage()
            {
                Category = category,
                Image = images[4],
            };
            tmpl.TemplateImages = new List<TemplateImage>() { img1, img2, img3, img4, img5 };
            tmpl.ImagesHash = tmpl.TemplateImages.GetSequenceHashCode();
            var result = DatabaseHelper.db().Query<Template>("Select * From Templates where ImagesHash=?", tmpl.ImagesHash).ToList();
            if (result.Count == 0)
            {
                DatabaseHelper.db().InsertAll(tmpl.TemplateImages);
                DatabaseHelper.db().Insert(tmpl);
                DatabaseHelper.db().UpdateWithChildren(tmpl);

                var employeeStored = DatabaseHelper.db().GetWithChildren<Template>(tmpl.Id);
            }


however the GetSequenceHashCode doesnt work as expected, it gives different results on every run, so i will have to check with another code.

For the current state of the app if only one image is found is enough but i might need in the future to know if all of the images are the same (and exist all of them in one template).

I can get what i want with this(check if all images exist i mean):

var result = DatabaseHelper.db().Query<TemplateImage>("Select * from TemplateImages where Image=?", images[0]).Count +
     DatabaseHelper.db().Query<TemplateImage>("Select * from TemplateImages where Image=?", images[1]).Count +
      DatabaseHelper.db().Query<TemplateImage>("Select * from TemplateImages where Image=?", images[2]).Count +
       DatabaseHelper.db().Query<TemplateImage>("Select * from TemplateImages where Image=?", images[3]).Count +
        DatabaseHelper.db().Query<TemplateImage>("Select * from TemplateImages where Image=?", images[4]).Count;


    ;//.ToList();
if (result.Count == 5)


But looks very bad to me, will this have impact on performance? is there any other way for the same result?

modified 8-Mar-20 22:23pm.

GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen8-Mar-20 21:50
professionalEddy Vluggen8-Mar-20 21:50 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 22:36
MemberExoskeletor8-Mar-20 22:36 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen8-Mar-20 22:44
professionalEddy Vluggen8-Mar-20 22:44 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 23:28
MemberExoskeletor8-Mar-20 23:28 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 0:18
professionalEddy Vluggen9-Mar-20 0:18 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 0:21
MemberExoskeletor9-Mar-20 0:21 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 0:34
professionalEddy Vluggen9-Mar-20 0:34 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 0:39
MemberExoskeletor9-Mar-20 0:39 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 0:59
MemberExoskeletor9-Mar-20 0:59 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 1:01
professionalEddy Vluggen9-Mar-20 1:01 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 1:08
MemberExoskeletor9-Mar-20 1:08 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 1:13
professionalEddy Vluggen9-Mar-20 1:13 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 1:23
MemberExoskeletor9-Mar-20 1:23 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 1:33
MemberExoskeletor9-Mar-20 1:33 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 2:26
professionalEddy Vluggen9-Mar-20 2:26 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 2:38
MemberExoskeletor9-Mar-20 2:38 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 2:41
professionalEddy Vluggen9-Mar-20 2:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.