Click here to Skip to main content
15,175,575 members
Home / Discussions / C#
   

C#

 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 12:23
MemberExoskeletor8-Mar-20 12:23 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 14:28
professionalMycroft Holmes8-Mar-20 14:28 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 15:20
MemberExoskeletor8-Mar-20 15:20 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 15:51
professionalMycroft Holmes8-Mar-20 15:51 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 15:54
MemberExoskeletor8-Mar-20 15:54 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 15:56
MemberExoskeletor8-Mar-20 15:56 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 16:12
professionalMycroft Holmes8-Mar-20 16:12 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 17:02
MemberExoskeletor8-Mar-20 17: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 22:50
professionalEddy Vluggen8-Mar-20 22:50 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 23:36
MemberExoskeletor8-Mar-20 23:36 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen8-Mar-20 23:44
professionalEddy Vluggen8-Mar-20 23:44 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 0:28
MemberExoskeletor9-Mar-20 0:28 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 1:18
professionalEddy Vluggen9-Mar-20 1:18 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 1:21
MemberExoskeletor9-Mar-20 1:21 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 1:34
professionalEddy Vluggen9-Mar-20 1:34 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 1:39
MemberExoskeletor9-Mar-20 1:39 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 1:59
MemberExoskeletor9-Mar-20 1:59 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 2:01
professionalEddy Vluggen9-Mar-20 2:01 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 2:08
MemberExoskeletor9-Mar-20 2:08 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 2:13
professionalEddy Vluggen9-Mar-20 2:13 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 2:23
MemberExoskeletor9-Mar-20 2:23 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 2:33
MemberExoskeletor9-Mar-20 2:33 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 3:26
professionalEddy Vluggen9-Mar-20 3:26 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 3:38
MemberExoskeletor9-Mar-20 3:38 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 3:41
professionalEddy Vluggen9-Mar-20 3: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.