- Entity framework model generating weird error message
- CREATE TABLE security.aspnet_users (
- userid UUID NOT NULL,
- applicationname VARCHAR(255) NOT NULL,
- username VARCHAR(255),
- lastactivitydate TIMESTAMP,
- isanonymous INT,
- CONSTRAINT aspnet_users_userid_pk PRIMARY KEY (userid),
- CONSTRAINT aspnet_users_username_pk UNIQUE (username, applicationname)
- );
- CREATE TABLE security.aspnet_membership (
- userid UUID NOT NULL,
- password VARCHAR(255),
- passwordsalt VARCHAR(255),
- passwordformat INT,
- email VARCHAR(255),
- passwordquestion VARCHAR(255),
- passwordanswer VARCHAR(255),
- comments VARCHAR(255),
- isapproved INT,
- islockedout INT,
- creationdate TIMESTAMP,
- lastlogindate TIMESTAMP,
- lastpasswordchangeddate TIMESTAMP,
- lastlockoutdate TIMESTAMP,
- failedpasswordattemptcount INT,
- failedpasswordattemptstart TIMESTAMP,
- failedpasswordanswercount INT,
- failedpasswordanswerstart TIMESTAMP,
- CONSTRAINT aspnet_membership_userid_pk PRIMARY KEY (userid),
- CONSTRAINT aspnet_membership_userid_ref FOREIGN KEY (userid) REFERENCES security.aspnet_users (userid)
- );
- CREATE TABLE security.aspnet_profiles (
- userid UUID,
- propertynames BYTEA NOT NULL,
- propertyvaluesstring BYTEA NOT NULL,
- propertyvaluesbinary BYTEA NULL,
- lastupdateddate TIMESTAMP NOT NULL,
- CONSTRAINT aspnet_profiles_userid_ref FOREIGN KEY (userid) REFERENCES security.aspnet_users (userid),
- CONSTRAINT aspnet_profiles_userid_key UNIQUE (userid)
- );
- public static void SaveUserProfile( CarSystemEntities context, UserProfileData data ) {
- if ( context == null )
- throw new ArgumentNullException( "context", "You must pass a non-null CarSystemEntities instance." );
- if ( data == null )
- throw new ArgumentNullException( "data", "You must pass a non-null UserProfileData instance." );
- try {
- Profile profile = null;
- if ( !context.Profiles.Any( p => p.Userid == data.ID ) ) {
- profile = new CarSystem.Profile{
- LastUpdatedDate = data.LastUpdatedDate.LocalDateTime,
- PropertyNames = data.PropertyNames,
- PropertyValuesBinary = data.PropertyValuesBinary,
- PropertyValuesString = data.PropertyValuesString,
- Userid = data.ID
- };
- context.Profiles.AddObject( profile );
- } else {
- profile = QueryUerProfiles( context ).Where( p => p.Userid == data.ID ).Single();
- if ( profile.LastUpdatedDate != data.LastUpdatedDate ) profile.LastUpdatedDate = data.LastUpdatedDate.LocalDateTime;
- if ( profile.PropertyNames != data.PropertyNames ) profile.PropertyNames = data.PropertyNames;
- if ( profile.PropertyValuesBinary != data.PropertyValuesBinary ) profile.PropertyValuesBinary = data.PropertyValuesBinary;
- if ( profile.PropertyValuesString != data.PropertyValuesString ) profile.PropertyValuesString = data.PropertyValuesString;
- }
- } catch ( Exception ex ) {
- throw new DataAccessException( DataAccessOperation.SaveProfile, FailureReason.DatabaseError, ex );
- }
- }
- if ( !context.Profiles.Any( p => p.Userid == data.ID ) ) {
- profile = new CarSystem.Profile{
- LastUpdatedDate = data.LastUpdatedDate.LocalDateTime,
- PropertyNames = data.PropertyNames,
- PropertyValuesBinary = data.PropertyValuesBinary,
- PropertyValuesString = data.PropertyValuesString,
- Userid = data.ID
- //add the next line to ensure there is a pk field
- ID = Guid.NewGuid()
- };
- using ( CarSystemEntities context = new CarSystemEntities() ) {
- if ( context.Connection.State != ConnectionState.Open ) {
- context.Connection.Open();
- }
- DbTransaction transaction = context.Connection.BeginTransaction();
- try {
- <Data processing code here>
- transaction.Commit();
- } catch ( Exception ex ) {
- transaction.Rollback();
- <More exception code here as needed>
- }
- }