Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:46:45+00:00 2026-05-25T18:46:45+00:00

Given a parent child relationship between User and FailedLogin where a user has many

  • 0

Given a parent child relationship between User and FailedLogin where a user has many failed logins. I’d like to map this into

class User
{
    public virtual FailedLogin LastFailedLogin { get; set; }
}

class FailedLogin
{
    public virtual User User { get; set; }
    public virtual DateTime AttemptOn { get; set; }
}

So that the LastFailedLogin property contains the FailedLogin with the most recent AttemptOn date and time. If LastFailedLogin is set it should save that FailedLogin to the database (i.e. .Cascade.SaveUpdate()) Note, I do not want to map a collection of all FailedLogins for this user for performance reasons.

I have been totally unable to write a fluent mapping for this. How do I map this using Fluent NHibernate?

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        // What goes here for LastFailedLogin?
    }
}

public class FailedLoginMap: ClassMap<FailedLogin>
{
    public FailedLoginMap()
    {
        References(x => x.User).Not.Update();
        Map(x => x.AttemptOn).Not.Update();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:46:45+00:00Added an answer on May 25, 2026 at 6:46 pm

    The solution I settled on, which I’m not entirely happy with, is:

    public class User
    {
        private readonly IList failedLogins;
        public virtual FailedLogin LastFailedLogin
        {
            get
            {
                return failedLogins.FirstOrDefault();
            }
            set
            {
                failedLogins.Clear();
                failedLogins.Add(value);
            }
        }
    }
    
    public class UserMap : ClassMap<User>
    {
        HasMany(Reveal.Member<User, IEnumerable<FailedLogin>>("failedLogins"))
            .Where("FailedLoginID=(SELECT TOP 1 a.FailedLoginID FROM FailedLogin AS a " + 
                    "WHERE a.UserID = UserID ORDER BY a.AttemptOn DESC)")
            .Cascade.SaveUpdate().Access.CamelCaseField().Inverse();
    }
    

    This solution ensures that only a single FailedLogin is loaded with the User. It also handles correctly saving a new failed login that is associated to the user. Finally it ensures that the implementation is hidden from consumers of the User class. Unfortunately, this still imposes persistence concerns on the User class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this situation where I have a parent child relationship between two sets
I'm using Entity Framework 4 and have a one-to-many relationship between a parent and
I have some Oracle tables that represent a parent-child relationship. They look something like
Given you have a domain model with a simple parent / child relationship, and
My model is a simple parent/child representation looking like this public class Parent {
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have an OLAP Basically there is a dimension that has parent-child relationship. So
I am reading from MSDN this: A child window has only one parent window,
I have a parent-child relationship in an Oracle 9i database-table like: parent | child
Given a simple parent/child class structure. I want to use linqkit to apply a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.