Index the value of an Enum, not the string

两盒软妹~` 提交于 2019-12-02 07:17:23

You can do this by implementing ISolrFieldSerializer. If the type IsEnum, serialize by casting to int. Otherwise delegate to DefaultFieldSerializer. Use the other field serializers for reference.

Hooking up your field serializer depends on the chosen IoC container, check the container's documentation.

Try this:

[SolrField("gender")]
public int GenderAsInt
{
    get { return (int) Gender; }
    set { Gender = (Gender) value; }
}

public virtual Gender Gender { get; set; }

Also note that declaring your enum as [Flags] doesn't make much sense:

  • There will hardly be anyone both Male and Female
  • Male will be interpreted as the default in respect to the current values of enum fields
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!