Domanda

I'm new to Fluent NHibernate and I am having an issue inserting to a table which has an ID column set as INT IDENTITY(1,1).

My user map is as follows...

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("User");
        Id(x => x.Id).GeneratedBy.Native();
        Map(x => x.FirstName);
        Map(x => x.LastName);
        Map(x => x.Company);
        Map(x => x.EmailAddress);
        Map(x => x.Password);
        Map(x => x.CountryId); 
    }

}

I want SQL to handle the identity of the user and I don't want to return anything. I've tried GeneratedBy.Identity() and I keep getting a SQL string that has question marks for the values on insert with the error message "Incorrect Syntax near the Keyword User'.

SQL String :

INSERT INTO User (FirstName, LastName, Company, EmailAddress, Password, CountryId) VALUES (?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()

Can anyone point me in the right direction???

È stato utile?

Soluzione

User is reserved word so it raises an error.

Try [User] (with these brackets) instead, like the following.

Table("[User]");


See also: http://technet.microsoft.com/en-us/library/aa238507%28v=sql.80%29.aspx

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top