how can I pass an array to a execute store command?

后端 未结 2 1415
甜味超标
甜味超标 2021-01-21 20:50

How to pass an array of integer separated by comma to an ExecuteStoreCommandin the entities as a parameter I am not able to execute this :

this.Obj         


        
2条回答
  •  鱼传尺愫
    2021-01-21 21:34

    Same approach as the answer, just demonstrating using strongly typed result set.

    void Main()
    {
        int[] operationIds = { 1000, 1001 };
        var result = ObjectContext.ExecuteStoreQuery(
                            $@"SELECT OperationId, Name, OfficialId, IsPatientEncrypted FROM Patient WHERE OperationId IN ({string.Join(",", operationIds)})");
                            result.Dump();
    }
    

    Dump method is a method in Linqpad. Screenshot of working sample in Linqpad 5:

    As the accepted answer said:

    • Build a query string against the store where you build up the IN clause using for example string.Join to build up the comma separated array of string values
      • When using ExecuteStoreQuery you can in case you use a SELECT project the data into a strongly typed entity of your choice - as long as its properties and respective property types match up with database contents such that Entity Framework can successfully materialize the contents into the POCO object you use as a generic argument.

提交回复
热议问题