-1

I have Linq Expression as below, which executes on DocumentDB SQL API on CosmosDB database.

predicate = predicate.And(x => x.SystemID== "123");

When I execute it to the context it by default generate SQL statement like below.

select * from [Table] where SystemID == "123"

But Expected query is below

select * from [Table] where id == "123"

But My Database table has a column named id and the Model property has name SystemID.
How can I put serialization logic to resolve that property name?

Note: I don't want to use AutoMapper.

Nick Chapsas
  • 6,872
  • 1
  • 20
  • 29
  • Is this default or expected select * from [Table] where id == "123"?? – Shivani Katukota May 22 '18 at 09:33
  • This is expected, my mistake let me correct my question – Bhavesh Kashikar May 22 '18 at 09:37
  • I used to be doing something similar for [Cosmonaut](https://github.com/Elfocrash/Cosmonaut) in order to add an extra expression. Check the methods in [ExpressionExtensions.cs](https://github.com/Elfocrash/Cosmonaut/blob/develop/Cosmonaut/Extensions/ExpressionExtensions.cs). You can potentially override the parameter name. – Nick Chapsas May 22 '18 at 09:47

1 Answers1

1

Using the [JsonProperty("id")] attribute on your property will make the LinqToCosmosSQL provider to take it into account and translate it to id.

Nick Chapsas
  • 6,872
  • 1
  • 20
  • 29
  • This is correct, however this fix will serialize my api response and rename property to id which I don't want. I want to use SystemID at fronend side. – Bhavesh Kashikar May 22 '18 at 09:41
  • Well you can't really have your cake and eat it too. Your best option would be to use the SQL itself. – Nick Chapsas May 22 '18 at 09:42