Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use Unique and Length with MySQL database #316

Open
kingjuk opened this issue Aug 3, 2015 · 7 comments
Open

Can't use Unique and Length with MySQL database #316

kingjuk opened this issue Aug 3, 2015 · 7 comments

Comments

@kingjuk
Copy link

kingjuk commented Aug 3, 2015

I can't use Unique and Length with MySQL database. It will work with one or the other, but not both. Map(x=> x.Name).Length(4001).Unique() won't event create the table for that class

@chester89 chester89 changed the title I can't use Unique and Length with MySQL database. It will work with one or the other but not both. Example Map(x=> x.Name).Length(4001).Unique() won't event create the table for that class Can't use Unique and Length with MySQL database Aug 3, 2015
@chester89
Copy link
Collaborator

Any error messages? What versions of Fluent and NHibernate are you using?

@kingjuk
Copy link
Author

kingjuk commented Aug 3, 2015

no error messages. Just doesn't create the table.

Nhibernate 4.0.0.4000
Fluent 2.0.1.0
MySQL 5.6

On Mon, Aug 3, 2015 at 12:56 PM, Gleb Chermennov [email protected]
wrote:

Any error messages? What versions of Fluent and NHibernate are you using?


Reply to this email directly or view it on GitHub
#316 (comment)
.

@kingjuk
Copy link
Author

kingjuk commented Aug 3, 2015

Here is the offending object attached.

If you change the line in EventMap

      Map(x => x.Name).Length(4001);

to
Map(x => x.Name).Length(4001).Unique();

It will not create the table and you will not get an error.

On Mon, Aug 3, 2015 at 1:03 PM, Justin King [email protected] wrote:

no error messages. Just doesn't create the table.

Nhibernate 4.0.0.4000
Fluent 2.0.1.0
MySQL 5.6

On Mon, Aug 3, 2015 at 12:56 PM, Gleb Chermennov <[email protected]

wrote:

Any error messages? What versions of Fluent and NHibernate are you using?


Reply to this email directly or view it on GitHub
#316 (comment)
.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace SMDC.GIIEP.Models.Entities
{
public enum Security
{
Public,
Private,
AccessCode
}

public enum Scenario
{
    Exercise,
    Real,
    Training
};

public class Event
{
    public virtual int Id { get; set; }

    [Required]
    [RegularExpression("^[a-zA-Z0-9 ]+$", ErrorMessage = "No special characters allowed in the name")]
    [StringLength(500)]
    public virtual string Name { get; set; }

    [Display(Name = "Time Created")]
    public virtual DateTime TimeCreated { get; set; }

    public virtual bool IsActive { get; set; }

    public virtual Scenario Scenario { get; set; }

    [Display(Name = "Created By")]
    public virtual String CreatedBy { get; set; }

    public virtual bool ServerCreated { get; set; }

    public virtual int Participants { get; set; }

    public virtual int Videos { get; set; }

    public virtual DateTime LastAccessed { get; set; }


    [Display(Name = "Operation/Event Security")]
    public virtual Security EventSecurity { get; set; }


    [Display(Name = "Access Code")]
    //     [Foolproof.RequiredIfRegExMatch("MissionSecurity", "AccessCode")]
    [XmlIgnore]
    [Newtonsoft.Json.JsonIgnore]
    public virtual string AccessCode { get; set; }

    public virtual IList<string> PrivateUserAccessList { get; set; }
    public virtual IList<string> PrivateStatesAccessList { get; set; }

    public virtual IList<Mission> Missions { get; set; }

    public override string ToString()
    {
        return Name;
    }

    public override bool Equals(object obj)
    {
        return EntityEquals(obj as Event);
    }

    protected bool EntityEquals(Event other)
    {
        if (other == null)
        {
            return false;
        }
        else
        {
            // Compare transient instances.
            return Id == other.Id;
        }
    }
    public override int GetHashCode()
    {
        return Id.GetHashCode();
    }
}

}

using FluentNHibernate.Mapping;
using SMDC.GIIEP.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMDC.GIIEP.Models.Mappings
{
public class EventMap:ClassMap
{
public EventMap()
{

        //Table("GiiepEvents");
        Id(x => x.Id);
        Map(x => x.Name).Length(4001);
        Map(x => x.TimeCreated);
        Map(x => x.IsActive);
        Map(x => x.Scenario);
        Map(x => x.CreatedBy);

        Map(x => x.EventSecurity);
        Map(X => X.AccessCode).Length(4001);
        Map(x => x.Participants);
        Map(x => x.LastAccessed);

        HasMany(x => x.PrivateUserAccessList).Table("UserEventAccess").Element("UserName").Not.LazyLoad().Cascade.AllDeleteOrphan();
        HasMany(x => x.PrivateStatesAccessList).Table("StateEventAccess").Element("StateName").Not.LazyLoad().Cascade.AllDeleteOrphan();

        HasMany(x => x.Missions).LazyLoad().Cascade.AllDeleteOrphan();

        //Cache.ReadWrite();

    }
}

}

@chester89
Copy link
Collaborator

chester89 commented Aug 3, 2015

ok, let me try and reproduce that

@chester89
Copy link
Collaborator

chester89 commented Aug 12, 2015

Yep, I can confirm this is happening in 2.x (and it's not just MySQL). Let
me see what I can do

@chester89
Copy link
Collaborator

chester89 commented Aug 12, 2015

Surprisingly, the problem is not with Fluent itself - the xml mapping that
gets generated is correct (has both unique and length attributes set). Yet,
the end result is not what we expect.
I guess I'll report the bug in NHibernate bug tracker and see what comes up.
Thanks

chester89 added a commit to chester89/fluent-nhibernate that referenced this issue Aug 12, 2015
@kingjuk
Copy link
Author

kingjuk commented Aug 12, 2015

Awesome. Good deal. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants