Reallm .Net Linq String Operations











up vote
0
down vote

favorite












I have a list of location codes that are a concatenation of BUILDING/ROOM i.e. "BLD23223019" where the first 5 characters are the building. I split building code from the string and display it in one list for the user to select which then takes the user to a list of rooms within that building. So I pass the building code to the Room list to filter the rooms and I do this like:



 _realm = Realm.GetInstance(RealmInstance.RealmPath);
try
{
_locations = _realm.All<Building>().Where(x => x.BuildingCode.Contains(_room.RoomCode)).ToList();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

ListViewLocations.ItemsSource = _locations;


but it doesn't give me any results, instead I get a target invocation error and the inner exception is "This object belongs to a closed realm." This also happens if I use "Equals(_room.RoomCode). I can't understand why the realm would be closed just from the above code.



I'm new to Realm so maybe I'm doing something wrong, if anyone can point me in the right direction it would be much appreciated.



This is the inner exception that the above code throws




at Realms.NativeException.ThrowIfNecessary (System.Func`2[T,TResult]
overrider) [0x0000a] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Native/NativeException.cs:57
at Realms.MarshalHelpers.GetString
(Realms.MarshalHelpers+NativeCollectionGetter getter) [0x0002b] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/MarshalHelpers.cs:55
at Realms.ObjectHandle.GetString (System.IntPtr propertyIndex)
[0x00013] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Handles/ObjectHandle.cs:258
at Realms.RealmObject.GetStringValue (System.String propertyName)
[0x00000] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/RealmObject.cs:139
at AsssetMan.Models.Buildings.get_BuildingCode () [0x00014] in
D:ProjectsAssetManRealmAssetManAssetManModelsBuildings.cs:8

at (wrapper managed-to-native)
System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object,System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object parameters, System.Globalization.CultureInfo
culture) [0x00032] in <43dbbdc147f2482093d8409abb04c233>:0











share|improve this question
























  • If you put var bob = _room.RoomCode; on the previous line, and then use bob in the LINQ, does it work? If not, which line of code throws the exceptions?
    – mjwills
    Nov 11 at 22:06










  • Further to this, if I run this instead there is no error and the list displays as normal _locations = _realm.All<Buildings>().ToList();
    – GrindEspresso
    Nov 11 at 22:17












  • @mjwills yes tried that, also tried the getting the full list from above code, and tried extracting the rooms that match but even that doesn't work
    – GrindEspresso
    Nov 11 at 22:23










  • @mjwills, I hadn't tried what you suggested, thought I had, so I gave it a go and using a literal works. so there's something wrong with the variable being passed to the page.
    – GrindEspresso
    Nov 11 at 23:05















up vote
0
down vote

favorite












I have a list of location codes that are a concatenation of BUILDING/ROOM i.e. "BLD23223019" where the first 5 characters are the building. I split building code from the string and display it in one list for the user to select which then takes the user to a list of rooms within that building. So I pass the building code to the Room list to filter the rooms and I do this like:



 _realm = Realm.GetInstance(RealmInstance.RealmPath);
try
{
_locations = _realm.All<Building>().Where(x => x.BuildingCode.Contains(_room.RoomCode)).ToList();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

ListViewLocations.ItemsSource = _locations;


but it doesn't give me any results, instead I get a target invocation error and the inner exception is "This object belongs to a closed realm." This also happens if I use "Equals(_room.RoomCode). I can't understand why the realm would be closed just from the above code.



I'm new to Realm so maybe I'm doing something wrong, if anyone can point me in the right direction it would be much appreciated.



This is the inner exception that the above code throws




at Realms.NativeException.ThrowIfNecessary (System.Func`2[T,TResult]
overrider) [0x0000a] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Native/NativeException.cs:57
at Realms.MarshalHelpers.GetString
(Realms.MarshalHelpers+NativeCollectionGetter getter) [0x0002b] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/MarshalHelpers.cs:55
at Realms.ObjectHandle.GetString (System.IntPtr propertyIndex)
[0x00013] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Handles/ObjectHandle.cs:258
at Realms.RealmObject.GetStringValue (System.String propertyName)
[0x00000] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/RealmObject.cs:139
at AsssetMan.Models.Buildings.get_BuildingCode () [0x00014] in
D:ProjectsAssetManRealmAssetManAssetManModelsBuildings.cs:8

at (wrapper managed-to-native)
System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object,System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object parameters, System.Globalization.CultureInfo
culture) [0x00032] in <43dbbdc147f2482093d8409abb04c233>:0











share|improve this question
























  • If you put var bob = _room.RoomCode; on the previous line, and then use bob in the LINQ, does it work? If not, which line of code throws the exceptions?
    – mjwills
    Nov 11 at 22:06










  • Further to this, if I run this instead there is no error and the list displays as normal _locations = _realm.All<Buildings>().ToList();
    – GrindEspresso
    Nov 11 at 22:17












  • @mjwills yes tried that, also tried the getting the full list from above code, and tried extracting the rooms that match but even that doesn't work
    – GrindEspresso
    Nov 11 at 22:23










  • @mjwills, I hadn't tried what you suggested, thought I had, so I gave it a go and using a literal works. so there's something wrong with the variable being passed to the page.
    – GrindEspresso
    Nov 11 at 23:05













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a list of location codes that are a concatenation of BUILDING/ROOM i.e. "BLD23223019" where the first 5 characters are the building. I split building code from the string and display it in one list for the user to select which then takes the user to a list of rooms within that building. So I pass the building code to the Room list to filter the rooms and I do this like:



 _realm = Realm.GetInstance(RealmInstance.RealmPath);
try
{
_locations = _realm.All<Building>().Where(x => x.BuildingCode.Contains(_room.RoomCode)).ToList();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

ListViewLocations.ItemsSource = _locations;


but it doesn't give me any results, instead I get a target invocation error and the inner exception is "This object belongs to a closed realm." This also happens if I use "Equals(_room.RoomCode). I can't understand why the realm would be closed just from the above code.



I'm new to Realm so maybe I'm doing something wrong, if anyone can point me in the right direction it would be much appreciated.



This is the inner exception that the above code throws




at Realms.NativeException.ThrowIfNecessary (System.Func`2[T,TResult]
overrider) [0x0000a] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Native/NativeException.cs:57
at Realms.MarshalHelpers.GetString
(Realms.MarshalHelpers+NativeCollectionGetter getter) [0x0002b] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/MarshalHelpers.cs:55
at Realms.ObjectHandle.GetString (System.IntPtr propertyIndex)
[0x00013] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Handles/ObjectHandle.cs:258
at Realms.RealmObject.GetStringValue (System.String propertyName)
[0x00000] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/RealmObject.cs:139
at AsssetMan.Models.Buildings.get_BuildingCode () [0x00014] in
D:ProjectsAssetManRealmAssetManAssetManModelsBuildings.cs:8

at (wrapper managed-to-native)
System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object,System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object parameters, System.Globalization.CultureInfo
culture) [0x00032] in <43dbbdc147f2482093d8409abb04c233>:0











share|improve this question















I have a list of location codes that are a concatenation of BUILDING/ROOM i.e. "BLD23223019" where the first 5 characters are the building. I split building code from the string and display it in one list for the user to select which then takes the user to a list of rooms within that building. So I pass the building code to the Room list to filter the rooms and I do this like:



 _realm = Realm.GetInstance(RealmInstance.RealmPath);
try
{
_locations = _realm.All<Building>().Where(x => x.BuildingCode.Contains(_room.RoomCode)).ToList();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

ListViewLocations.ItemsSource = _locations;


but it doesn't give me any results, instead I get a target invocation error and the inner exception is "This object belongs to a closed realm." This also happens if I use "Equals(_room.RoomCode). I can't understand why the realm would be closed just from the above code.



I'm new to Realm so maybe I'm doing something wrong, if anyone can point me in the right direction it would be much appreciated.



This is the inner exception that the above code throws




at Realms.NativeException.ThrowIfNecessary (System.Func`2[T,TResult]
overrider) [0x0000a] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Native/NativeException.cs:57
at Realms.MarshalHelpers.GetString
(Realms.MarshalHelpers+NativeCollectionGetter getter) [0x0002b] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/MarshalHelpers.cs:55
at Realms.ObjectHandle.GetString (System.IntPtr propertyIndex)
[0x00013] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/Handles/ObjectHandle.cs:258
at Realms.RealmObject.GetStringValue (System.String propertyName)
[0x00000] in
/Users/realm/jenkins/workspace/realm_realm-dotnet_PR-1775/Realm/Realm/RealmObject.cs:139
at AsssetMan.Models.Buildings.get_BuildingCode () [0x00014] in
D:ProjectsAssetManRealmAssetManAssetManModelsBuildings.cs:8

at (wrapper managed-to-native)
System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object,System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object parameters, System.Globalization.CultureInfo
culture) [0x00032] in <43dbbdc147f2482093d8409abb04c233>:0








realm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 22:36

























asked Nov 11 at 22:04









GrindEspresso

112




112












  • If you put var bob = _room.RoomCode; on the previous line, and then use bob in the LINQ, does it work? If not, which line of code throws the exceptions?
    – mjwills
    Nov 11 at 22:06










  • Further to this, if I run this instead there is no error and the list displays as normal _locations = _realm.All<Buildings>().ToList();
    – GrindEspresso
    Nov 11 at 22:17












  • @mjwills yes tried that, also tried the getting the full list from above code, and tried extracting the rooms that match but even that doesn't work
    – GrindEspresso
    Nov 11 at 22:23










  • @mjwills, I hadn't tried what you suggested, thought I had, so I gave it a go and using a literal works. so there's something wrong with the variable being passed to the page.
    – GrindEspresso
    Nov 11 at 23:05


















  • If you put var bob = _room.RoomCode; on the previous line, and then use bob in the LINQ, does it work? If not, which line of code throws the exceptions?
    – mjwills
    Nov 11 at 22:06










  • Further to this, if I run this instead there is no error and the list displays as normal _locations = _realm.All<Buildings>().ToList();
    – GrindEspresso
    Nov 11 at 22:17












  • @mjwills yes tried that, also tried the getting the full list from above code, and tried extracting the rooms that match but even that doesn't work
    – GrindEspresso
    Nov 11 at 22:23










  • @mjwills, I hadn't tried what you suggested, thought I had, so I gave it a go and using a literal works. so there's something wrong with the variable being passed to the page.
    – GrindEspresso
    Nov 11 at 23:05
















If you put var bob = _room.RoomCode; on the previous line, and then use bob in the LINQ, does it work? If not, which line of code throws the exceptions?
– mjwills
Nov 11 at 22:06




If you put var bob = _room.RoomCode; on the previous line, and then use bob in the LINQ, does it work? If not, which line of code throws the exceptions?
– mjwills
Nov 11 at 22:06












Further to this, if I run this instead there is no error and the list displays as normal _locations = _realm.All<Buildings>().ToList();
– GrindEspresso
Nov 11 at 22:17






Further to this, if I run this instead there is no error and the list displays as normal _locations = _realm.All<Buildings>().ToList();
– GrindEspresso
Nov 11 at 22:17














@mjwills yes tried that, also tried the getting the full list from above code, and tried extracting the rooms that match but even that doesn't work
– GrindEspresso
Nov 11 at 22:23




@mjwills yes tried that, also tried the getting the full list from above code, and tried extracting the rooms that match but even that doesn't work
– GrindEspresso
Nov 11 at 22:23












@mjwills, I hadn't tried what you suggested, thought I had, so I gave it a go and using a literal works. so there's something wrong with the variable being passed to the page.
– GrindEspresso
Nov 11 at 23:05




@mjwills, I hadn't tried what you suggested, thought I had, so I gave it a go and using a literal works. so there's something wrong with the variable being passed to the page.
– GrindEspresso
Nov 11 at 23:05












1 Answer
1






active

oldest

votes

















up vote
1
down vote













Thanks to @mjwills I've figured it out. the first comment using var bob in the linq extension worked if I used a literal. That meant there had to be a problem with the variable or the way I was passing the BuildingCode to the RoomCode page. The message "Realm is closed", or something to that effect, had me stumped at first then I remembered that the Realm objects are "Live" and as I was closing the _realm on the previous page, the building object I was passing to the RoomCode page was no longer available. So I new'd up a building object and when the building was selected from the list of buildings, copied the building code into it and passed that to the lookup for the RoomCode so the BuildingCode was still available after the Realm is closed.
Thanks @mjwills.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253712%2freallm-net-linq-string-operations%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Thanks to @mjwills I've figured it out. the first comment using var bob in the linq extension worked if I used a literal. That meant there had to be a problem with the variable or the way I was passing the BuildingCode to the RoomCode page. The message "Realm is closed", or something to that effect, had me stumped at first then I remembered that the Realm objects are "Live" and as I was closing the _realm on the previous page, the building object I was passing to the RoomCode page was no longer available. So I new'd up a building object and when the building was selected from the list of buildings, copied the building code into it and passed that to the lookup for the RoomCode so the BuildingCode was still available after the Realm is closed.
    Thanks @mjwills.






    share|improve this answer

























      up vote
      1
      down vote













      Thanks to @mjwills I've figured it out. the first comment using var bob in the linq extension worked if I used a literal. That meant there had to be a problem with the variable or the way I was passing the BuildingCode to the RoomCode page. The message "Realm is closed", or something to that effect, had me stumped at first then I remembered that the Realm objects are "Live" and as I was closing the _realm on the previous page, the building object I was passing to the RoomCode page was no longer available. So I new'd up a building object and when the building was selected from the list of buildings, copied the building code into it and passed that to the lookup for the RoomCode so the BuildingCode was still available after the Realm is closed.
      Thanks @mjwills.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Thanks to @mjwills I've figured it out. the first comment using var bob in the linq extension worked if I used a literal. That meant there had to be a problem with the variable or the way I was passing the BuildingCode to the RoomCode page. The message "Realm is closed", or something to that effect, had me stumped at first then I remembered that the Realm objects are "Live" and as I was closing the _realm on the previous page, the building object I was passing to the RoomCode page was no longer available. So I new'd up a building object and when the building was selected from the list of buildings, copied the building code into it and passed that to the lookup for the RoomCode so the BuildingCode was still available after the Realm is closed.
        Thanks @mjwills.






        share|improve this answer












        Thanks to @mjwills I've figured it out. the first comment using var bob in the linq extension worked if I used a literal. That meant there had to be a problem with the variable or the way I was passing the BuildingCode to the RoomCode page. The message "Realm is closed", or something to that effect, had me stumped at first then I remembered that the Realm objects are "Live" and as I was closing the _realm on the previous page, the building object I was passing to the RoomCode page was no longer available. So I new'd up a building object and when the building was selected from the list of buildings, copied the building code into it and passed that to the lookup for the RoomCode so the BuildingCode was still available after the Realm is closed.
        Thanks @mjwills.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 23:40









        GrindEspresso

        112




        112






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253712%2freallm-net-linq-string-operations%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)