# GetFeatureById returns new Feature when Id not found

**URL:** <https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280>\
**Category:** WinForms\
**Created:** [August 6, 2013, 5:15pm UTC](https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280 "2013-08-06T17:15:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@Anthony](https://community.thinkgeo.com/u/Anthony)\
**Post date:** [August 6, 2013, 5:15pm UTC](https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280/1 "2013-08-06T17:15:20Z")

</div>

I&nbsp;have&nbsp;some&nbsp;code&nbsp;where&nbsp;a&nbsp;feature&nbsp;can&nbsp;be&nbsp;in&nbsp;one&nbsp;of&nbsp;two&nbsp;layers.&nbsp;In&nbsp;MapSuite&nbsp;6.0,&nbsp;the&nbsp;GetFeatureById&nbsp;function&nbsp;would&nbsp;feature&nbsp;an&nbsp;Id&nbsp;of&nbsp;null&nbsp;if&nbsp;the&nbsp;feature&nbsp;was&nbsp;not&nbsp;found.&nbsp;I&nbsp;used&nbsp;this&nbsp;to&nbsp;search&nbsp;for&nbsp;the&nbsp;feature&nbsp;in&nbsp;the&nbsp;other&nbsp;layer.  
  
  
  
Anyway,&nbsp;the&nbsp;problem&nbsp;is&nbsp;this.&nbsp;If&nbsp;the&nbsp;feature&nbsp;is&nbsp;not&nbsp;found&nbsp;in&nbsp;a&nbsp;layer&nbsp;while&nbsp;using&nbsp;GetFeatureById,&nbsp;a&nbsp;feature&nbsp;with&nbsp;an&nbsp;Id&nbsp;is&nbsp;still&nbsp;returned.&nbsp;Additionally,&nbsp;this&nbsp;new&nbsp;feature&nbsp;also&nbsp;has&nbsp;an&nbsp;Id.&nbsp;Is&nbsp;this&nbsp;supposed&nbsp;to&nbsp;be&nbsp;how&nbsp;this&nbsp;function&nbsp;works?&nbsp;I&nbsp;would&nbsp;think&nbsp;if&nbsp;it&nbsp;couldn’t&nbsp;find&nbsp;a&nbsp;feature&nbsp;with&nbsp;the&nbsp;given&nbsp;Id,&nbsp;then&nbsp;it&nbsp;would&nbsp;return&nbsp;null.  
  
  
  
I&nbsp;could&nbsp;compare&nbsp;the&nbsp;feature&nbsp;id&nbsp;returned&nbsp;with&nbsp;the&nbsp;id&nbsp;I&nbsp;passed&nbsp;in,&nbsp;but&nbsp;it&nbsp;would&nbsp;be&nbsp;easier&nbsp;to&nbsp;just&nbsp;check&nbsp;if&nbsp;the&nbsp;returned&nbsp;feature&nbsp;is&nbsp;null&nbsp;or&nbsp;not.

---

<div class="post-metadata">

**Author:** ![Summer1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@Summer1](https://community.thinkgeo.com/u/Summer1)\
**Post date:** [August 7, 2013, 4:45am UTC](https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280/2 "2013-08-07T04:45:25Z")

</div>

Hi&nbsp;Anthony,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;post,I&nbsp;agree&nbsp;with&nbsp;you&nbsp;that&nbsp;returning&nbsp;null&nbsp;would&nbsp;better&nbsp;if&nbsp;there&nbsp;is&nbsp;no&nbsp;feature&nbsp;matches.&nbsp;However,&nbsp;for&nbsp;now&nbsp;we&nbsp;can’t&nbsp;do&nbsp;the&nbsp;change&nbsp;to&nbsp;make&nbsp;the&nbsp;feature&nbsp;return&nbsp;null&nbsp;if&nbsp;the&nbsp;feature&nbsp;doesn’t&nbsp;be&nbsp;found.&nbsp;As&nbsp;this&nbsp;change&nbsp;is&nbsp;a&nbsp;breaking&nbsp;change&nbsp;which&nbsp;might&nbsp;bring&nbsp;many&nbsp;troubles&nbsp;for&nbsp;other&nbsp;users.&nbsp;  
&nbsp;&nbsp;  
&nbsp;As&nbsp;the&nbsp;method&nbsp;will&nbsp;never&nbsp;return&nbsp;null,&nbsp;So,&nbsp;to&nbsp;judge&nbsp;if(returnedFeature.Id==null)&nbsp;would&nbsp;be&nbsp;a&nbsp;walkaround.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Sorry&nbsp;for&nbsp;the&nbsp;inconvenience.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Summer

---

<div class="post-metadata">

**Author:** ![Anthony](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@Anthony](https://community.thinkgeo.com/u/Anthony)\
**Post date:** [August 7, 2013, 9:12am UTC](https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280/3 "2013-08-07T09:12:11Z")

</div>

Thanks&nbsp;for&nbsp;the&nbsp;fast&nbsp;reply!&nbsp;In&nbsp;MapSuite&nbsp;7.0,&nbsp;the&nbsp;returnedFeature.Id&nbsp;actually&nbsp;has&nbsp;a&nbsp;GUID&nbsp;value.&nbsp;In&nbsp;MapSuite&nbsp;6.0,&nbsp;the&nbsp;Id&nbsp;used&nbsp;to&nbsp;be&nbsp;null&nbsp;if&nbsp;the&nbsp;feature&nbsp;was&nbsp;not&nbsp;found,&nbsp;and&nbsp;that’s&nbsp;what&nbsp;I&nbsp;used&nbsp;to&nbsp;key&nbsp;off&nbsp;of.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Anyway,&nbsp;I&nbsp;can&nbsp;compare&nbsp;the&nbsp;returnedFeature.Id&nbsp;to&nbsp;the&nbsp;feature.Id&nbsp;I&nbsp;was&nbsp;looking&nbsp;for,&nbsp;as&nbsp;a&nbsp;workaround.I&nbsp;just&nbsp;wanted&nbsp;to&nbsp;make&nbsp;sure&nbsp;I&nbsp;wasn’t&nbsp;missing&nbsp;anything.&nbsp;Thanks

---

<div class="post-metadata">

**Author:** ![Summer1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@Summer1](https://community.thinkgeo.com/u/Summer1)\
**Post date:** [August 8, 2013, 3:07am UTC](https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280/4 "2013-08-08T03:07:54Z")

</div>

Hi&nbsp;Anthony,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Sorry&nbsp;for&nbsp;the&nbsp;mistake,&nbsp;you&nbsp;are&nbsp;right,&nbsp;a&nbsp;guid&nbsp;will&nbsp;be&nbsp;there&nbsp;and&nbsp;"compare&nbsp;the&nbsp;returnedFeature.Id&nbsp;to&nbsp;the&nbsp;feature.Id"&nbsp;should&nbsp;be&nbsp;a&nbsp;good&nbsp;walkaround.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Whenever&nbsp;you&nbsp;have&nbsp;any&nbsp;more&nbsp;question&nbsp;,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Best&nbsp;Regards&nbsp;  
&nbsp;&nbsp;  
&nbsp;Summer

---

<div class="post-metadata">

**Author:** ![Anthony](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@Anthony](https://community.thinkgeo.com/u/Anthony)\
**Post date:** [August 8, 2013, 8:08am UTC](https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280/5 "2013-08-08T08:08:20Z")

</div>

Thanks&nbsp;for&nbsp;the&nbsp;quick&nbsp;replies!

---

<div class="post-metadata">

**Author:** ![Summer1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@Summer1](https://community.thinkgeo.com/u/Summer1)\
**Post date:** [August 8, 2013, 8:40pm UTC](https://community.thinkgeo.com/t/getfeaturebyid-returns-new-feature-when-id-not-found/2280/6 "2013-08-08T20:40:30Z")

</div>

Hi&nbsp;Anthony,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;are&nbsp;always&nbsp;welcome,if&nbsp;you&nbsp;have&nbsp;any&nbsp;more&nbsp;question&nbsp;,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Best&nbsp;Regards&nbsp;  
&nbsp;&nbsp;  
&nbsp;Summer
