public UserLoginsMap() { CompositeId().KeyProperty(x => x.LoginProvider).KeyProperty(x => x.ProviderKey); Map(x => x.ProviderDisplayName).Nullable(); References(x => x.User).Column("UserId").ForeignKey("UserLogin_User"); Table("UserLogin"); SchemaAction.Validate(); }
public ChatMessageMap() { Id(x => x.Id).GeneratedBy.GuidComb(); Map(x => x.CreationTime).Not.Nullable(); References(x => x.User).Not.Nullable().Column("UserId").ForeignKey("fChatUserUser"); References(x => x.ChatRoom) .Not.Nullable().Column("ChatRoomId") .ForeignKey("fChatUserChatRoom"); DiscriminateSubClassesOnColumn("MessageType"); SchemaAction.Validate(); }
public TransactionMap() { Id(x => x.Id).GeneratedBy.GuidComb(); References(x => x.User) .Column("User_id").ForeignKey("Transaction_User").Not.Nullable(); Map(x => x.Created).Not.Nullable(); Map(z => z.Action).Not.Nullable(); Map(z => z.Type).Not.Nullable(); Map(z => z.Price).Not.Nullable().CustomSqlType("smallmoney"); DiscriminateSubClassesOnColumn("TransactionType"); SchemaAction.Validate(); }
public QuestionMap() { DynamicUpdate(); //https://stackoverflow.com/a/7084697/1235448 Id(x => x.Id).GeneratedBy.HiLo(nameof(HiLoGenerator), nameof(HiLoGenerator.NextHi), "10", $"{nameof(HiLoGenerator.TableName)}='{nameof(Question)}'"); Map(x => x.Text).Length(8000).Not.Nullable(); //Map(x => x.Attachments).Nullable(); Map(x => x.Created).Not.Nullable().Not.Update(); Map(x => x.Updated).Not.Nullable(); //Map(x => x.Language).Length(10); //Map(x => x.Subject).Nullable().Column("Subject_id").CustomType<QuestionSubject?>(); References(x => x.User).Column("UserId") .ForeignKey("Question_User").Not.Nullable(); //References(x => x.CorrectAnswer).Column("CorrectAnswer_id").ForeignKey("Question_Answer").Nullable(); References(x => x.University).Column("UniversityId").ForeignKey("Question_University").Nullable(); References(x => x.Course).Not.Nullable().Column("CourseId").ForeignKey("Question_Course").Nullable(); HasMany(x => x.Answers).Access.CamelCaseField(Prefix.Underscore) .Inverse() .ExtraLazyLoad() .Cascade.AllDeleteOrphan(); //DO NOT PUT ANY CASCADE WE HANDLE THIS ON CODE - TAKE A LOOK AT ADMIN COMMAND AND REGULAR COMMAND //HasMany(x => x.Transactions) // //.Cascade.() // .LazyLoad() // .Inverse(); //HasMany(x => x.Votes).Access.CamelCaseField(Prefix.Underscore) // .KeyColumns.Add("QuestionId") // .Cascade.AllDeleteOrphan(); //Map(m => m.VoteCount).Not.Nullable(); Component(x => x.Status); SchemaAction.Validate(); //DiscriminateSubClassesOnColumn("State");//.Formula($"case when State is Null then 'Ok' else State end"); }
public VoteMap() { // nhibernate doesn't support multiple unique key on the same column Id(x => x.Id).GeneratedBy.GuidComb(); References(x => x.User) //.UniqueKey("uq_VotesUserDocument") //.UniqueKey("uq_VotesUserAnswer") //.UniqueKey("uq_VotesUserQuestion") .Column("UserId").Not.Nullable().ForeignKey("Votes_User"); References(x => x.Document) //.UniqueKey("uq_VotesUserDocument") .Column("DocumentId").Nullable().ForeignKey("Votes_Document"); //References(x => x.Answer) // //.UniqueKey("uq_VotesUserAnswer") // .Column("AnswerId").Nullable().ForeignKey("Votes_Answer"); //References(x => x.Question) // //.UniqueKey("uq_VotesUserQuestion") // .Column("QuestionId").Nullable().ForeignKey("Votes_Question"); Map(x => x.VoteType).CustomType <VoteType>().Not.Nullable(); Component(x => x.TimeStamp); SchemaAction.Validate(); }
public UniversityMap() { DynamicUpdate(); Id(x => x.Id).GeneratedBy.GuidComb(); Map(x => x.Name).UniqueKey("uq_UniversityNameCountry"); Map(x => x.Extra); Map(x => x.UsersCount); Map(x => x.Image).Column("ImageUrl"); Map(x => x.Country).Not.Nullable().Length(2).UniqueKey("uq_UniversityNameCountry"); Component(x => x.RowDetail); //HasMany(x => x.Documents) // .ReadOnly() // .Access.CamelCaseField(Prefix.Underscore) // .Cascade.None(); //HasMany(x => x.Questions) // .ReadOnly() // .Access.CamelCaseField(Prefix.Underscore).Cascade.None(); //HasMany(x => x.Users) // .ReadOnly() // .Access.CamelCaseField(Prefix.Underscore).Cascade.None(); Map(x => x.State).CustomType <GenericEnumStringType <ItemState> >().Not.Nullable(); SchemaAction.Validate(); }
public ViewConversationMap() { Id(x => x.Id); Map(x => x.LastMessage); Map(x => x.UserName); Map(x => x.UserPhoneNumber); Map(x => x.UserEmail); Map(x => x.UserId); Map(x => x.TutorName); Map(x => x.TutorPhoneNumber); Map(x => x.TutorEmail); Map(x => x.TutorId); Map(x => x.Status).CustomType <EnumerationType <ChatRoomStatus> >(); Map(x => x.AssignTo); Map(x => x.RequestFor); Map(x => x.ConversationStatus); Map(x => x.StudyRoomExists); Map(x => x.HoursFromLastMessage); Map(x => x.Country); SchemaAction.Validate(); Table("vAdminConversation"); ReadOnly(); /* * alter VIEW [sb].[vAdminConversation] * * as * with cte as ( * Select * cr.Id , * cra.status2 as status, * cra.AssignTo, * cr.Identifier , * cr.UpdateTime as lastMessage, * u.id as userId, * u.Name, * u.Email, * u.PhoneNumberHash, * CONCAT(l.CourseId, ' ', l.Text) as RequestFor, * case when (select top 1 UserId from sb.ChatMessage cm where cm.ChatRoomId = cr.id ) = cu.userid then 0 else 1 end as isTutor * * from sb.ChatUser cu * join sb.ChatRoom cr on cu.ChatRoomId = cr.Id * left join sb.ChatRoomAdmin cra * on cr.Id = cra.Id * join sb.[user] u on cu.UserId = u.Id * left join sb.Lead l on cra.LeadId = l.Id * ) * select c.Identifier as id, * c.lastMessage as lastMessage, * c.Name as UserName, * c.PhoneNumberHash as UserPhoneNumber, * c.Email as UserEmail, * c.userId as UserId, * d.Name as TutorName, * d.PhoneNumberHash as TutorPhoneNumber, * d.Email as TutorEmail, * d.UserId as TutorId, * c.status, * c.AssignTo, * c.RequestFor, * (SELECT max (grp) FROM * ( * SELECT *, COUNT(isstart) OVER( PARTITION BY ChatRoomId ORDER BY Id ROWS UNBOUNDED PRECEDING) AS grp * FROM ( * SELECT *, * CASE WHEN ABS(UserId - LAG(UserId) OVER(PARTITION BY ChatRoomId ORDER BY Id)) <= 1 THEN NULL ELSE 1 END AS isstart * FROM sb.ChatMessage * where ChatRoomId = c.id * ) t1 * ) t2) as conversationStatus, * case when (Select id from sb.StudyRoom where Identifier = c.Identifier) is null then 0 else 1 end as studyRoomExists, * datediff(HOUR, c.lastMessage, GETUTCDATE()) as HoursFromLastMessage * from cte c * inner join cte d on d.id = c.id and c.isTutor = 0 and d.isTutor = 1 */ }