.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Mapping table without primary key in Nhibernate

Posted By:      Posted Date: October 20, 2010    Points: 0   Category :ASP.Net

How can we map a table without having primary key in nHibernate.

I have a table which does not contain any primary key, so how can i map this table in .hbm.xml file.

Please advice.

View Complete Post

More Related Resource Links

Using table with no primary key in CTP4



Does anyone knows if CTP 4.0 supports table with no primary key. I know Entity framework does.

Can't perform Create, Update or Delete operations on 'Table(outbox)' because it has no primary ke



I'm a beginner in asp.net and I have some problem inserting data into sql server 2005 with linq.


my code is : 


        Dim Result As New SMS.SendResult
        If Result.status = 0 Then
            Label1.Text = "Your Message Sent Successfuly"
            Dim db As New IGSSDataContext
            Dim out As New outbox With {.ClientID = intRandomNumber, .From = User.Identity.Name, .TO = TextBox1.TabIndex, _
            .Time = Now, .Message = Message}
            out.ID = (ID)
            TextBox1.Text = ""

Error Message: The referenced table must have a primary or candidate key. [ FK Name = FK_tblA_tblB ]

An Entity Data Model is used to generate the script to create  a SQL CE database.  It creates all of the 10+ tables and their primary keys without any problem. A lot of foreign key creations generate errors like the following: SQL Execution Error. Executed SQL statement ALTER TABLE [tblA] ADD CONSTRAINT [FK_tblA_tblB] FOREIGN KEY([A], [B], [C]) REFERENCES [tblB]([A], [BBB], [C]) Error Source: SQL Server Compact ADO.NET Data Provider Error Message: The referenced table must have a primary or candidate key. [ FK Name = FK_tblA_tblB ] The primary keys are there and correct. Could anyone offer some tips on how to figure out what is wrong?hz

Cannot Insert records in table using NHibernate

I am very much new with NHibernate. I am inserting a new record in the table. However, it seems that it does not insert. What I'm using is Fluent NHibernate.Below is the code which inserts records. public virtual void Save(string CreatedBy) { ISession NHSession = Star.CNPL_BusinessObjects.Common.Session.OpenSession(); ITransaction NHTransaction = NHSession.BeginTransaction(); try { this.Save(CreatedBy, NHSession); NHTransaction.Commit(); NHSession.Flush(); } catch (Exception ex) { NHTransaction.Rollback(); throw ex; } } public virtual void Save(string CreatedBy, ISession Session) { try { if (this.IsPersisted) { this.SaveAuditTrail(Session, false, CreatedBy); Session.SaveOrUpdateCopy(this); } else { Session.Save(this); } } catch (Exception ex) { throw ex; } }

Cannot add record in table using NHibernate

Hi there!I'm new to NHibernate and I need help on this issue.No records where inserted in my SQL Table after committing the transaction or after the .Flush() method. I checked the code and it follows the correct sequence of codes. I can't seem to find any other way where the error fails.

Retrieving users from mapping/pivot table

I have three tables.CustomProfileUserID (pk)DisplayNameCompanyIDTeamsTeamRecordID (Pk)TeamIDCompanyIDEmployeesInTeamsUserIDTeamIDI want to assign employees to teams via a gridview control with a templated checkbox.I have a dropdownlist control to select the TeamID.I am having problems with the select statement.The gridview needs to select employees that are not assigned to any teams as well as assigned to other teams. An employee can be assigned to many teams.What I have been trying is:cp.UserID, cp.DisplayName, et.TeamIntID, cp.CompanyID FROM            EmployeesInTeams AS et CROSS JOIN                          CustomProfile AS cp WHERE        (et.TeamIntID <> @TeamIntID) AND (NOT EXISTS                              (SELECT        TeamIntID, UserID                                FROM            EmployeesInTeams                                WHERE        (cp.UserID = UserID))) AND (cp.CompanyID = @companyid)Select cp.UserID, cp.DisplayName, et.TeamIntID, cp.C

Table mapping

 Hi friend, I want to know what is the use of table mappings.At what scenario we will use table mapping. Thanks  

Two Primary key for table???

i HAVE FOLLOWING SCRIPT TO CREATE TABLE. create table Grade_report (STUDENT_NUMBER SMALLINT NOT NULL, SECTION_ID SMALLINT NOT NULL, GRADE CHAR(1), CONSTRAINT stno_secid PRIMARY KEY (STUDENT_NUMBER, SECTION_ID)) tHE BOLD line shows that it has two primary key. would that be possible to create two primary key for a single table??  If not then what does it for?? may be unique key??? anyone can explain me please.     Thanks,      

adding Primary key to a data table

Hi All, I have a data table this table saves values from a form's add button and binds to a gridview on the final submit button adds to the data base. See my Data table below    DataTable dt = new DataTable();                   if (ViewState["CompDetails"] == null)            {                 dt.Columns.Add("CourseCode");                dt.Columns.Add("CourseName");                dt.Columns.Add("Fees");            }            else                dt = (DataTable)ViewState["CompDetails"];            DataRow dr = dt.NewRow();                                &n

Joins on non-indexed fields and table primary keys.


I have two tables (a,b) each with a primary key (which are clustered indexes). When I issue the t-sql statement

delete XX from t1 XX inner join t2 on (xx.A2 = t2

Data Flows in SSIS - Mapping Multiple source tables to Destination table **Newb question**

Hi I am new to SSIS and had a basic question. I have around 30+ tables in a db that needs to be migrated to a newer schema in the DB. The data flow task seems to be ideally suited for my requirement. My question is do I need to create 30+ different data flow tasks for this which will get executed one after the other or is there a better way to migrate large number of tables. Also how are referential constraints taken care of during such migration. Thanks and Regards, Ganesh Ranganathan
Ganesh Ranganathan
[Please mark the post as answer if it answers your question]

Update records related to primary table in sql


HI All,

For example

I have 2 tables  Person and Person_Child.

In Person table i have columns

Id, PersonId,PersonName,PersonAdrress,PersonAge,RowId


rowid is identity


and in the person_child table--here parentrowid refers to parent table rowid and again rowid is identity here

Id, PersonId,PersonName,PersonAdrress,PersonAge,ParentRowid,RowId




I need to update the child table values as it is in parent tables where it is null.

I have to do for many tables.

Is there any way to do it dynamically.







What is the best way to get the primary key column name of a table in a stored procedure ?


I'm writing a stored procedure which manipulates a table whose name must be given as a parameter. The stored procedure needs the primary key column name (by design the primary key must have only one column), and I thought I could get this from the system table instead of having to provide it as a parameter. So I need to put the primary key column name in a variable.

The best way I found so far is this :

declare @keyname nvarchar(1024)
table #keys (table_qualifier nvarchar(255),table_owner nvarchar(255),table_name nvarchar

Mapping custom values and columns to destination table **Newb question**



I am copying data from one source to destination SQL CE table using the data flow task. I have two extra requirements which I am not sure how to achieve.

1.)  One source column needs to be mapped to two destination columns. In the column mapping dropdown the column name disappears after mapping it to one destination column.

2) some custom values for columns need to be added, which are not present in source. For e.g. a default value for some destination columns which is not present.

Any pointers would be extremely appreciated. Thanks,

Ganesh Ranganathan
[Please mark the post as answer if it answers your question]

Partitioned Table vs Primary Key aggrevation

I've got a large fact table that contains a TimeStamp column and an ID column.   The table is partitioned on the TimeStamp column.  Up until now it has never had a Primary Key.  However, now I would like to create a PK on the ID column, because I am building another table that has a FK that references the ID column of my existing table.

And it looks like I can't.

I can't add a PK or Alternate Key to the partitioned table unless the key includes the partitioning column.   If I include the Partitioning column in the Key, I have to include it in the FK of the other table, which isn't an option.. at least, not one I'm willing to take.

Please tell me there's a work-around for this, somebody... I already know that I could enforce RI by other means;  but I'm hoping for a work-around that allows me to put a PK on this partitioned table.

Nhibernate Mapping exception


i  am getting  an error

Association references unmapped class: Jinnah.ObjectPersistanceLayer.Classes.TPF_Teacher_Performance

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.MappingException: Association references unmapped class: Jinnah.ObjectPersistanceLayer.Classes.TPF_Teacher_Performance

Source Error:

Line 21:                 c.Configure(this._configureFilePath);
Line 22:                 c.AddXmlFile(this._objectMappingPath);
Line 23:                 _factory = c.BuildSessionFactory();
Line 24:             }
Line 25:             return _factory.OpenSession();

Source File: C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\ERP-QA-Solution\Jinnah.NhibernateDAL\Data.cs    Line: 23




I  have checked all mapping files , and classes .

also  set  the Embeded resource   property of&n

Select Primary Key Column of Table returns 0 rows


I have three tables: Design, Box, Wall.

Design has a column DesignId that is a GUID. It does not allow nulls, is unique, and is the primary key. The identity is set to false for compatibility with Entity Framework v4.

Box has  a column BoxId that is a GUID. It does not allow nulls, is unique, and is the primary key. The identity is set to false as well.

Box also has a column DesignId that is a GUID. It does not allow nulls, is not unique and is not the primary key.

Wall has  a column WallId that is a GUID. It does not allow nulls, is unique, and is the primary key. The identity is set to false as well.

Wall also has a column DesignId that is a GUID. It does not allow nulls, is not unique and is not the primary key.

Wall also has a column BoxId that is a GUID. It does not allow nulls, is not unique and is not the primary key.

Box.DesignId has been set as a ForeignKey relating to Design.DesignId.

Wall.DesignId has been set as a ForeignKey relating to Design.DesignId

Wall.BoxId has been set as a ForeignKey relating to Box.BoxId.


If I execute      SELECT DesignId FROM Design     I see the correct number of rows.

If I execute     SELECT BoxId From Box        I see zer

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend