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
realm
add a comment |
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
realm
If you putvar bob = _room.RoomCode;
on the previous line, and then usebob
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
add a comment |
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
realm
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
realm
edited Nov 11 at 22:36
asked Nov 11 at 22:04
GrindEspresso
112
112
If you putvar bob = _room.RoomCode;
on the previous line, and then usebob
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
add a comment |
If you putvar bob = _room.RoomCode;
on the previous line, and then usebob
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 11 at 23:40
GrindEspresso
112
112
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
If you put
var bob = _room.RoomCode;
on the previous line, and then usebob
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