0

I reproduced the problem by creating a small sample with an entity called Employee and an enum called EmployeeStatus. I then created a method called LoadByStatus. The problem is the first line of the method throws an exception when the enum parameter is set to employeed. There are other things wrong as I commented out the if statement and it generated a SQL exception.

public static System.Data.IDataReader PageDataLoadByStatus(CodeFluent.Runtime.PageOptions pageOptions, DemoLoadByEnum.EmployeeStatus status)
{
    if ((status == DemoLoadByEnum.EmployeeStatus.Employeed))
    {
        throw new System.ArgumentNullException("status");
    }
    CodeFluent.Runtime.CodeFluentPersistence persistence = CodeFluentContext.Get(DemoLoadByEnum.Constants.DemoLoadByEnumStoreName).Persistence;
    persistence.CreateStoredProcedureCommand(null, "Employee", "LoadByStatus");
    persistence.AddParameterEnumInt32("@status", status, DemoLoadByEnum.EmployeeStatus.Employeed);
    if ((pageOptions != null))
    {
        System.Collections.IEnumerator enumerator = pageOptions.OrderByArguments.GetEnumerator();
        bool b;
        int index = 0;
        for (b = enumerator.MoveNext(); b; b = enumerator.MoveNext())
        {
            CodeFluent.Runtime.OrderByArgument argument = ((CodeFluent.Runtime.OrderByArgument)(enumerator.Current));
            persistence.AddParameter(string.Format("@_orderBy{0}", index), argument.Name);
            persistence.AddParameter(string.Format("@_orderByDirection{0}", index), ((int)(argument.Direction)));
            index = (index + 1);
        }
    }
    System.Data.IDataReader reader = CodeFluentContext.Get(DemoLoadByEnum.Constants.DemoLoadByEnumStoreName).Persistence.ExecuteReader();
    return reader;
}

Below is Employee entity

  <cf:entity name="Employee" namespace="DemoLoadByEnum">
    <cf:property name="Id" key="true" />
    <cf:property name="Name" entityDisplay="true" />
    <cf:property name="Status" typeName="{0}.EmployeeStatus" />
    <cf:method name="LoadByStatus" body="LOAD(DemoLoadByEnum.EmployeeStatus status) WHERE Status = @status" />
  </cf:entity>

Below is my Enum

  <cf:enumeration name="EmployeeStatus" namespace="DemoLoadByEnum">
    <cf:enumerationValue name="Employeed" />
    <cf:enumerationValue name="Released" />
  </cf:enumeration>
Dave
  • 649
  • 5
  • 13

1 Answers1

0

CodeFluent Entities has a notion of default value. Simon's answer explains this concept: https://stackoverflow.com/a/35790190/2996339

The common way to solve your problem is to add an enumeration value which act as the default value (None/Unset/Unspecified/...), or change the default value.

Another way is to set Use Persistence Default Value to False at method parameter, method or enumeration level.

Community
  • 1
  • 1
meziantou
  • 20,589
  • 7
  • 64
  • 83
  • Did you mean set Use Persistence Default Value to False. It was already set to True and setting it to False seems to have done the trick. – Dave Nov 21 '16 at 10:39