Nhibernate 'Invalid column name' error when a column exists

Hi I have an object called document and one user user

Document

public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual User User { get; set; } 

Documentmap

  public DocumentMap() { Map(x => x.Name); Map(x => x.Description); References(x => x.User); } 

User

  public virtual string UserId { get; set; } public virtual string FirstName { get; set; } public virtual string MiddleInitial { get; set; } public virtual string LastName { get; set; } private readonly IList<Document> _documents = new List<Document>(); public virtual IEnumerable<Document> Documents { get { return _documents; } } public virtual void Remove(Document document) { _documents.Remove(document); } public virtual void Add(Document document) { if (!document.IsNew() && _documents.Contains(document)) return; _documents.Add(document); } Map(x => x.UserId); Map(x => x.FirstName); Map(x => x.MiddleInitial); Map(x => x.LastName); HasMany(x => x.Documents).Access.CamelCaseField(Prefix.Underscore); 

Pretty straighforward (they inherit from the base class with things like createddate modifieddate, etc.)

when i try to get all documents using userid i get this

Invalid column name 'UserId'.

the column is most definitely in the table. It also lists some elements of the base class that do not exist.

I take sql and pass it in the query manager, and I get intellisense saying that they are invalid columns. I run it and it runs fine. In addition, there are many other objects that use these base classes without problems.

I tried various things, for example, explicit matching of a key name, a column name using the reverse, etc. to no avail. I do not know what to do. Thanks, Raifa

// EDIT on request, sorry, this is so much. database is created using nhibernate schema

Document

 public class Document : Entity { public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual DocumentCategory DocumentCategory { get; set; } [ValueOf(typeof(DocumentFileType))] public virtual string FileType { get; set; } public virtual string FileUrl { get; set; } public virtual int? Pages { get; set; } public virtual decimal? Size { get; set; } public virtual User User { get; set; } } public class DocumentMap : EntityMap<Document> { public DocumentMap() { Map(x => x.Name); Map(x => x.Description); Map(x => x.FileUrl); Map(x => x.Pages); Map(x => x.Size); Map(x => x.FileType); References(x => x.DocumentCategory); References(x => x.User); } } 

An object

 public class Entity : IGridEnabledClass, IEquatable<Entity> { public virtual int EntityId { get; set; } public virtual DateTime? CreateDate { get; set; } public virtual DateTime? ChangeDate { get; set; } public virtual int ChangedBy { get; set; } public virtual bool Archived { get; set; } public virtual bool IsNew() { return EntityId == 0; } 

User

  public class User : DomainEntity, IUser { public virtual string UserId { get; set; } [ValidateNonEmpty] public virtual string FirstName { get; set; } public virtual string MiddleInitial { get; set; } [ValidateNonEmpty] public virtual string LastName { get; set; } public virtual string Title { get; set; } public virtual DateTime? BirthDate { get; set; } public virtual string StartPage { get; set; } public virtual UserLoginInfo UserLoginInfo { get; set; } public virtual UserStatus UserStatus { get; set; } public virtual Photo HeadShot { get; set; } private readonly IList<Document> _documents = new List<Document>(); public virtual IEnumerable<Document> Documents { get { return _documents; } } public virtual void Remove(Document document) { _documents.Remove(document); } public virtual void Add(Document document) { if (!document.IsNew() && _documents.Contains(document)) return; _documents.Add(document); } several more collections public class UserMap : DomainEntityMap<User> { public UserMap() { Map(x => x.UserId); Map(x => x.FirstName); Map(x => x.MiddleInitial); Map(x => x.LastName); Map(x => x.BirthDate); Map(x => x.StartPage); References(x => x.UserStatus); References(x => x.UserLoginInfo); References(x => x.HeadShot); HasMany(x => x.Documents).Access.CamelCaseField(Prefix.Underscore); 

database tables create from script select menu item in management studio

  SELECT [EntityId] ,[CreateDate] ,[ChangeDate] ,[ChangedBy] ,[Archived] ,[Name] ,[Description] ,[FileUrl] ,[Pages] ,[Size] ,[FileType] ,[DocumentCategoryId] ,[UserId] FROM [DecisionCriticalSuite].[dbo].[Document] GO SELECT [EntityId] ,[CreateDate] ,[ChangeDate] ,[ChangedBy] ,[Archived] ,[TenantId] ,[OrgId] ,[UserId] ,[FirstName] ,[MiddleInitial] ,[LastName] ,[BirthDate] ,[StartPage] ,[UserStatusId] ,[UserLoginInfoId] ,[HeadShotId] ,[OrganizationId] FROM [DecisionCriticalSuite].[dbo].[User] GO 

error from nhprof

 ERROR: Invalid column name 'UserId'. Invalid column name 'UserId'. Invalid column name 'EntityId'. Invalid column name 'EntityId'. Invalid column name 'CreateDate'. Invalid column name 'ChangeDate'. Invalid column name 'ChangedBy'. Invalid column name 'Archived'. Invalid column name 'FileType'. Invalid column name 'UserId'.Could not execute query: SELECT documents0_.UserId as UserId1_, documents0_.EntityId as EntityId1_, documents0_.EntityId as EntityId49_0_, documents0_.CreateDate as CreateDate49_0_, documents0_.ChangeDate as ChangeDate49_0_, documents0_.ChangedBy as ChangedBy49_0_, documents0_.Archived as Archived49_0_, documents0_.Name as Name49_0_, documents0_.Description as Descript7_49_0_, documents0_.FileUrl as FileUrl49_0_, documents0_.Pages as Pages49_0_, documents0_.Size as Size49_0_, documents0_.FileType as FileType49_0_, documents0_.DocumentCategoryId as Documen12_49_0_, documents0_.UserId as UserId49_0_ FROM [Document] documents0_ WHERE documents0_.UserId=@p0 
+4
source share
1 answer

Make sure nhibernate is querying the same database as the query in sql management studio.

+17
source

All Articles