Page 1 of 1

Cannot create method for a storage function X that can be composed.

Posted: Wed 21 Sep 2016 11:22
by dzwiedziu
I encountered a problem where I can't map function from database to model.
Why only stored procedures can be mapped? It's a big problem, because now I must make a stored procedure that use function, it would be fine but I can't use it in Linq (Entity Framework 6) when making select on Entity, as procedure generated in context class is voidable.
Generated C# function goes like this:

Code: Select all

public virtual void StoredProcedure (string OWNER, global::System.Nullable<decimal> OWNER_ID, string RODZ_DOK_IDS, global::System.Nullable<decimal> LICZ_PUSTE, ref global::System.Nullable<decimal> RES)
        {
            EntityConnection connection = ((IObjectContextAdapter)this).ObjectContext.Connection as EntityConnection;
            bool needClose = false;
            if (connection.State != ConnectionState.Open) {
              connection.Open();
              needClose = true;
            }

			try {
              using(EntityCommand command = new EntityCommand())
              {
                if (((IObjectContextAdapter)this).ObjectContext.CommandTimeout.HasValue)
                  command.CommandTimeout = ((IObjectContextAdapter)this).ObjectContext.CommandTimeout.Value;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = @"Entity.StoredProcedure";
                command.Connection = connection;
                EntityParameter OWNERParameter = new EntityParameter("OWNER", System.Data.DbType.String);
                OWNERParameter.Direction = ParameterDirection.Input;
                if (OWNER != null)
                    OWNERParameter.Value = OWNER;
                command.Parameters.Add(OWNERParameter);
                EntityParameter OWNER_IDParameter = new EntityParameter("OWNER_ID", System.Data.DbType.Decimal);
                OWNER_IDParameter.Direction = ParameterDirection.Input;
                if (OWNER_ID.HasValue)
                    OWNER_IDParameter.Value = OWNER_ID;
                command.Parameters.Add(OWNER_IDParameter);
                EntityParameter RODZ_DOK_IDSParameter = new EntityParameter("RODZ_DOK_IDS", System.Data.DbType.String);
                RODZ_DOK_IDSParameter.Direction = ParameterDirection.Input;
                if (RODZ_DOK_IDS != null)
                    RODZ_DOK_IDSParameter.Value = RODZ_DOK_IDS;
                command.Parameters.Add(RODZ_DOK_IDSParameter);
                EntityParameter LICZ_PUSTEParameter = new EntityParameter("LICZ_PUSTE", System.Data.DbType.Decimal);
                LICZ_PUSTEParameter.Direction = ParameterDirection.Input;
                if (LICZ_PUSTE.HasValue)
                    LICZ_PUSTEParameter.Value = LICZ_PUSTE;
                command.Parameters.Add(LICZ_PUSTEParameter);
                EntityParameter RESParameter = new EntityParameter("RES", System.Data.DbType.Decimal);
                RESParameter.Direction = ParameterDirection.Output;
                if (RES.HasValue)
                    RESParameter.Value = RES;
                command.Parameters.Add(RESParameter);
                command.ExecuteNonQuery();
                if (RESParameter.Value != null && !(RESParameter.Value is System.DBNull))
                  RES = (global::System.Nullable<decimal>)RESParameter.Value;
                else
                  RES = default(global::System.Nullable<decimal>);
              }
            }
            finally {
              if (needClose)
                connection.Close();
            }
        }
So only option to get values is through ref to variable which can't be used in Linq.
Is there a different way to use function in model, even as stored procedure but with return value as function and not as ref to variable?

This is a solution I am using now viewtopic.php?t=17083
But this is problematic as I wrote before. This solution make new request on database each time i get a record from database, in case where i get 1000 records this makes 1 request for each record.

Re: Cannot create method for a storage function X that can be composed.

Posted: Thu 22 Sep 2016 13:04
by Shalex

Re: Cannot create method for a storage function X that can be composed.

Posted: Fri 23 Sep 2016 08:51
by dzwiedziu
Thank you for your response, but when we can expect a solution for functions in ED?

Re: Cannot create method for a storage function X that can be composed.

Posted: Mon 26 Sep 2016 13:37
by Shalex
The investigation is in progress. As soon as we have any results, we will let you know.

Re: Cannot create method for a storage function X that can be composed.

Posted: Thu 06 Oct 2016 16:05
by Shalex
The generation of static methods by the EntityObject template is supported via the new property Direct Call of EntityMethod in the new build: viewtopic.php?f=32&t=34376.