0

I have a class Client which has a attribute of dogs

public class ClientsMap : ClassMap<Clients>
{
    public ClientsMap()
    {           
        Id(x => x.ClientID);
        HasMany(x => x.Dogs);
    }
}

public class Client
{

    public virtual IList<Dog> Dogs { get; set; }
    public virtual int ClientID { get; set; }
}

and a class of dog that references client.

public class Dog
{
    public virtual Clients Client { get; private set; }
    public virtual int Id { get; set; }
}

public class DogMap : ClassMap<Dog>
{
    public DogMap()
    {
        Table("Pooches");
        Id(x => x.Id);

        References(x => x.Client).Column("ClientId");
    }

}

Because I am mapping on to an existing DB i cannot change the field names.

When I try and return the dogs collection I am getting an invalid column error on client_id with the SQL

SELECT 
dogs0_.Clients_id as Clients3_1_, 
dogs0_.Id as Id1_, 
dogs0_.Id as Id1_0_, 
dogs0_.ClientId as ClientId1_0_ 
FROM 
pooches dogs0_ 

How can I make this use clientid over cliet_id. I thought I specified this in the dogs map.

1 Answer 1

1

You should also specify the column name on the one to many relationship.

HasMany(x => x.Dogs)
    .KeyColumn("ClientId");
Sign up to request clarification or add additional context in comments.

1 Comment

i know its would be something simple... Couldn't find the answer in TFM.. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.