- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
SaveEntity() produces INSERT statement with missing values
Joined: 03-Sep-2009
ORMSupportClasses Version: 2.6.9.616
We are having trouble inserting a new entity into the database. The SQL output for the SaveEntity() function call is as follows:
Query: INSERT INTO [DBA].[NonWorkTime] ([CompanyId], [PaycodeId], [Amount]) VALUES (?, ?, ?)
Parameter: @CompanyId : Int32. Length: 4. Precision: 0. Scale: 0. Direction: Input. Value: 1.
Parameter: @PaycodeId : Int32. Length: 4. Precision: 0. Scale: 0. Direction: Input. Value: 30.
Parameter: @Amount : Int64. Length: 8. Precision: 0. Scale: 0. Direction: Input. Value: 72000000000.
The NonWorkTimeEntity also contains the ApplyDate and EmployeeId fields which are not present in the INSERT statement. Since the columns in the database are not nullable, and an exception is generated. Strangely, all of the fields of the Entity can be successfully modified with an UPDATE (SaveEntity())and the entity may also be removed from the database with DELETE (DeleteEntity()). The only SQL command that doesn’t appear to be working is INSERT. The entity current contains custom code, but there was no success even after removing it. All custom converters on the entity were removed without success as well. Dropping the entity from the LLBLGen project, refreshing the catalogue, re-adding the entity, then re-generating did not fix the problem.
This is the generated entity code:
///////////////////////////////////////////////////////////////
// This is generated code.
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 2.6
// Code is generated on:
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version:
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
#if !CF
using System.Runtime.Serialization;
#endif
using System.Xml.Serialization;
using PayclockDAL;
using PayclockDAL.HelperClasses;
using PayclockDAL.FactoryClasses;
using PayclockDAL.RelationClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
namespace PayclockDAL.EntityClasses
{
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
// __LLBLGENPRO_USER_CODE_REGION_END
/// <summary>
/// Entity class which represents the entity 'NonWorkTime'.<br/><br/>
///
/// </summary>
[Serializable]
public partial class NonWorkTimeEntity : CommonEntityBase, ISerializable
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
// __LLBLGENPRO_USER_CODE_REGION_END
{
#region Class Member Declarations
private CompanyEntity _company;
private EmployeeEntity _employee;
private PaycodeEntity _paycode;
// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
// __LLBLGENPRO_USER_CODE_REGION_END
#endregion
#region Statics
private static Dictionary<string, string> _customProperties;
private static Dictionary<string, Dictionary<string, string>> _fieldsCustomProperties;
/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
public static partial class MemberNames
{
/// <summary>Member name Company</summary>
public static readonly string Company = "Company";
/// <summary>Member name Employee</summary>
public static readonly string Employee = "Employee";
/// <summary>Member name Paycode</summary>
public static readonly string Paycode = "Paycode";
}
#endregion
/// <summary> Static CTor for setting up custom property hashtables. Is executed before the first instance of this entity class or derived classes is constructed. </summary>
static NonWorkTimeEntity()
{
SetupCustomPropertyHashtables();
}
/// <summary> CTor</summary>
public NonWorkTimeEntity():base("NonWorkTimeEntity")
{
InitClassEmpty(null, CreateFields());
}
/// <summary> CTor</summary>
/// <remarks>For framework usage.</remarks>
/// <param name="fields">Fields object to set as the fields for this entity.</param>
public NonWorkTimeEntity(IEntityFields2 fields):base("NonWorkTimeEntity")
{
InitClassEmpty(null, fields);
}
/// <summary> CTor</summary>
/// <param name="validator">The custom validator object for this NonWorkTimeEntity</param>
public NonWorkTimeEntity(IValidator validator):base("NonWorkTimeEntity")
{
InitClassEmpty(validator, CreateFields());
}
/// <summary> CTor</summary>
/// <param name="companyId">PK value for NonWorkTime which data should be fetched into this NonWorkTime object</param>
/// <param name="nonWorkTimeId">PK value for NonWorkTime which data should be fetched into this NonWorkTime object</param>
/// <remarks>The entity is not fetched by this constructor. Use a DataAccessAdapter for that.</remarks>
public NonWorkTimeEntity(System.Int32 companyId, System.Int32 nonWorkTimeId):base("NonWorkTimeEntity")
{
InitClassEmpty(null, CreateFields());
this.CompanyId = companyId;
this.NonWorkTimeId = nonWorkTimeId;
}
/// <summary> CTor</summary>
/// <param name="companyId">PK value for NonWorkTime which data should be fetched into this NonWorkTime object</param>
/// <param name="nonWorkTimeId">PK value for NonWorkTime which data should be fetched into this NonWorkTime object</param>
/// <param name="validator">The custom validator object for this NonWorkTimeEntity</param>
/// <remarks>The entity is not fetched by this constructor. Use a DataAccessAdapter for that.</remarks>
public NonWorkTimeEntity(System.Int32 companyId, System.Int32 nonWorkTimeId, IValidator validator):base("NonWorkTimeEntity")
{
InitClassEmpty(validator, CreateFields());
this.CompanyId = companyId;
this.NonWorkTimeId = nonWorkTimeId;
}
/// <summary> Protected CTor for deserialization</summary>
/// <param name="info"></param>
/// <param name="context"></param>
[EditorBrowsable(EditorBrowsableState.Never)]
protected NonWorkTimeEntity(SerializationInfo info, StreamingContext context) : base(info, context)
{
if(SerializationHelper.Optimization != SerializationOptimization.Fast)
{
_company = (CompanyEntity)info.GetValue("_company", typeof(CompanyEntity));
if(_company!=null)
{
_company.AfterSave+=new EventHandler(OnEntityAfterSave);
}
_employee = (EmployeeEntity)info.GetValue("_employee", typeof(EmployeeEntity));
if(_employee!=null)
{
_employee.AfterSave+=new EventHandler(OnEntityAfterSave);
}
_paycode = (PaycodeEntity)info.GetValue("_paycode", typeof(PaycodeEntity));
if(_paycode!=null)
{
_paycode.AfterSave+=new EventHandler(OnEntityAfterSave);
}
base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance());
}
// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
// __LLBLGENPRO_USER_CODE_REGION_END
}
/// <summary>Performs the desync setup when an FK field has been changed. The entity referenced based on the FK field will be dereferenced and sync info will be removed.</summary>
/// <param name="fieldIndex">The fieldindex.</param>
protected override void PerformDesyncSetupFKFieldChange(int fieldIndex)
{
switch((NonWorkTimeFieldIndex)fieldIndex)
{
case NonWorkTimeFieldIndex.CompanyId:
DesetupSyncPaycode(true, false);
DesetupSyncEmployee(true, false);
DesetupSyncCompany(true, false);
break;
case NonWorkTimeFieldIndex.EmployeeId:
DesetupSyncEmployee(true, false);
break;
case NonWorkTimeFieldIndex.PaycodeId:
DesetupSyncPaycode(true, false);
break;
default:
base.PerformDesyncSetupFKFieldChange(fieldIndex);
break;
}
}
/// <summary>Gets the inheritance info provider instance of the project this entity instance is located in. </summary>
/// <returns>ready to use inheritance info provider instance.</returns>
protected override IInheritanceInfoProvider GetInheritanceInfoProvider()
{
return InheritanceInfoProviderSingleton.GetInstance();
}
/// <summary> Sets the related entity property to the entity specified. If the property is a collection, it will add the entity specified to that collection.</summary>
/// <param name="propertyName">Name of the property.</param>
/// <param name="entity">Entity to set as an related entity</param>
/// <remarks>Used by prefetch path logic.</remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public override void SetRelatedEntityProperty(string propertyName, IEntity2 entity)
{
switch(propertyName)
{
case "Company":
this.Company = (CompanyEntity)entity;
break;
case "Employee":
this.Employee = (EmployeeEntity)entity;
break;
case "Paycode":
this.Paycode = (PaycodeEntity)entity;
break;
default:
break;
}
}
/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
public override RelationCollection GetRelationsForFieldOfType(string fieldName)
{
return NonWorkTimeEntity.GetRelationsForField(fieldName);
}
/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
public static RelationCollection GetRelationsForField(string fieldName)
{
RelationCollection toReturn = new RelationCollection();
switch(fieldName)
{
case "Company":
toReturn.Add(NonWorkTimeEntity.Relations.CompanyEntityUsingCompanyId);
break;
case "Employee":
toReturn.Add(NonWorkTimeEntity.Relations.EmployeeEntityUsingCompanyIdEmployeeId);
break;
case "Paycode":
toReturn.Add(NonWorkTimeEntity.Relations.PaycodeEntityUsingCompanyIdPaycodeId);
break;
default:
break;
}
return toReturn;
}
#if !CF
/// <summary>Checks if the relation mapped by the property with the name specified is a one way / single sided relation. If the passed in name is null, it
/// will return true if the entity has any single-sided relation</summary>
/// <param name="propertyName">Name of the property which is mapped onto the relation to check, or null to check if the entity has any relation/ which is single sided</param>
/// <returns>true if the relation is single sided / one way (so the opposite relation isn't present), false otherwise</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool CheckOneWayRelations(string propertyName)
{
// use template trick to calculate the # of single-sided / oneway relations
int numberOfOneWayRelations = 0;
switch(propertyName)
{
case null:
return ((numberOfOneWayRelations > 0) || base.CheckOneWayRelations(null));
default:
return base.CheckOneWayRelations(propertyName);
}
}
#endif
/// <summary> Sets the internal parameter related to the fieldname passed to the instance relatedEntity. </summary>
/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public override void SetRelatedEntity(IEntity2 relatedEntity, string fieldName)
{
switch(fieldName)
{
case "Company":
SetupSyncCompany(relatedEntity);
break;
case "Employee":
SetupSyncEmployee(relatedEntity);
break;
case "Paycode":
SetupSyncPaycode(relatedEntity);
break;
default:
break;
}
}
/// <summary> Unsets the internal parameter related to the fieldname passed to the instance relatedEntity. Reverses the actions taken by SetRelatedEntity() </summary>
/// <param name="relatedEntity">Instance to unset as the related entity of type entityType</param>
/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
/// <param name="signalRelatedEntityManyToOne">if set to true it will notify the manytoone side, if applicable.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public override void UnsetRelatedEntity(IEntity2 relatedEntity, string fieldName, bool signalRelatedEntityManyToOne)
{
switch(fieldName)
{
case "Company":
DesetupSyncCompany(false, true);
break;
case "Employee":
DesetupSyncEmployee(false, true);
break;
case "Paycode":
DesetupSyncPaycode(false, true);
break;
default:
break;
}
}
/// <summary> Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields). These entities will have to be persisted after this entity during a recursive save.</summary>
/// <returns>Collection with 0 or more IEntity2 objects, referenced by this entity</returns>
public override List<IEntity2> GetDependingRelatedEntities()
{
List<IEntity2> toReturn = new List<IEntity2>();
return toReturn;
}
/// <summary> Gets a collection of related entities referenced by this entity which this entity depends on (this entity is the FK side of their PK fields). These
/// entities will have to be persisted before this entity during a recursive save.</summary>
/// <returns>Collection with 0 or more IEntity2 objects, referenced by this entity</returns>
public override List<IEntity2> GetDependentRelatedEntities()
{
List<IEntity2> toReturn = new List<IEntity2>();
if(_company!=null)
{
toReturn.Add(_company);
}
if(_employee!=null)
{
toReturn.Add(_employee);
}
if(_paycode!=null)
{
toReturn.Add(_paycode);
}
return toReturn;
}
/// <summary>Gets a list of all entity collections stored as member variables in this entity. The contents of the ArrayList is used by the DataAccessAdapter to perform recursive saves. Only 1:n related collections are returned.</summary>
/// <returns>Collection with 0 or more IEntityCollection2 objects, referenced by this entity</returns>
public override List<IEntityCollection2> GetMemberEntityCollections()
{
List<IEntityCollection2> toReturn = new List<IEntityCollection2>();
return toReturn;
}
/// <summary>ISerializable member. Does custom serialization so event handlers do not get serialized. Serializes members of this entity class and uses the base class' implementation to serialize the rest.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
[EditorBrowsable(EditorBrowsableState.Never)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (SerializationHelper.Optimization != SerializationOptimization.Fast)
{
info.AddValue("_company", (!this.MarkedForDeletion?_company:null));
info.AddValue("_employee", (!this.MarkedForDeletion?_employee:null));
info.AddValue("_paycode", (!this.MarkedForDeletion?_paycode:null));
}
// __LLBLGENPRO_USER_CODE_REGION_START GetObjectInfo
// __LLBLGENPRO_USER_CODE_REGION_END
base.GetObjectData(info, context);
}
/// <summary>Returns true if the original value for the field with the fieldIndex passed in, read from the persistent storage was NULL, false otherwise.
/// Should not be used for testing if the current value is NULL, use <see cref="TestCurrentFieldValueForNull"/> for that.</summary>
/// <param name="fieldIndex">Index of the field to test if that field was NULL in the persistent storage</param>
/// <returns>true if the field with the passed in index was NULL in the persistent storage, false otherwise</returns>
public bool TestOriginalFieldValueForNull(NonWorkTimeFieldIndex fieldIndex)
{
return base.Fields[(int)fieldIndex].IsNull;
}
/// <summary>Returns true if the current value for the field with the fieldIndex passed in represents null/not defined, false otherwise.
/// Should not be used for testing if the original value (read from the db) is NULL</summary>
/// <param name="fieldIndex">Index of the field to test if its currentvalue is null/undefined</param>
/// <returns>true if the field's value isn't defined yet, false otherwise</returns>
public bool TestCurrentFieldValueForNull(NonWorkTimeFieldIndex fieldIndex)
{
return base.CheckIfCurrentFieldValueIsNull((int)fieldIndex);
}
/// <summary>Gets a list of all the EntityRelation objects the type of this instance has.</summary>
/// <returns>A list of all the EntityRelation objects the type of this instance has. Hierarchy relations are excluded.</returns>
public override List<IEntityRelation> GetAllRelations()
{
return new NonWorkTimeRelations().GetAllRelations();
}
/// <summary> Creates a new IRelationPredicateBucket object which contains the predicate expression and relation collection to fetch
/// the related entity of type 'Company' to this entity. Use DataAccessAdapter.FetchNewEntity() to fetch this related entity.</summary>
/// <returns></returns>
public virtual IRelationPredicateBucket GetRelationInfoCompany()
{
IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(new FieldCompareValuePredicate(CompanyFields.CompanyId, null, ComparisonOperator.Equal, this.CompanyId));
return bucket;
}
/// <summary> Creates a new IRelationPredicateBucket object which contains the predicate expression and relation collection to fetch
/// the related entity of type 'Employee' to this entity. Use DataAccessAdapter.FetchNewEntity() to fetch this related entity.</summary>
/// <returns></returns>
public virtual IRelationPredicateBucket GetRelationInfoEmployee()
{
IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(new FieldCompareValuePredicate(EmployeeFields.CompanyId, null, ComparisonOperator.Equal, this.CompanyId));
bucket.PredicateExpression.Add(new FieldCompareValuePredicate(EmployeeFields.EmployeeId, null, ComparisonOperator.Equal, this.EmployeeId));
return bucket;
}
/// <summary> Creates a new IRelationPredicateBucket object which contains the predicate expression and relation collection to fetch
/// the related entity of type 'Paycode' to this entity. Use DataAccessAdapter.FetchNewEntity() to fetch this related entity.</summary>
/// <returns></returns>
public virtual IRelationPredicateBucket GetRelationInfoPaycode()
{
IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(new FieldCompareValuePredicate(PaycodeFields.CompanyId, null, ComparisonOperator.Equal, this.CompanyId));
bucket.PredicateExpression.Add(new FieldCompareValuePredicate(PaycodeFields.PaycodeId, null, ComparisonOperator.Equal, this.PaycodeId));
return bucket;
}
/// <summary>Creates entity fields object for this entity. Used in constructor to setup this entity in a polymorphic scenario.</summary>
protected virtual IEntityFields2 CreateFields()
{
return EntityFieldsFactory.CreateEntityFieldsObject(PayclockDAL.EntityType.NonWorkTimeEntity);
}
/// <summary>
/// Creates the ITypeDefaultValue instance used to provide default values for value types which aren't of type nullable(of T)
/// </summary>
/// <returns></returns>
protected override ITypeDefaultValue CreateTypeDefaultValueProvider()
{
return new TypeDefaultValue();
}
/// <summary>Creates a new instance of the factory related to this entity</summary>
protected override IEntityFactory2 CreateEntityFactory()
{
return EntityFactoryCache2.GetEntityFactory(typeof(NonWorkTimeEntityFactory));
}
#if !CF
/// <summary>Adds the member collections to the collections queue (base first)</summary>
/// <param name="collectionsQueue">The collections queue.</param>
protected override void AddToMemberEntityCollectionsQueue(Queue<IEntityCollection2> collectionsQueue)
{
base.AddToMemberEntityCollectionsQueue(collectionsQueue);
}
/// <summary>Gets the member collections queue from the queue (base first)</summary>
/// <param name="collectionsQueue">The collections queue.</param>
protected override void GetFromMemberEntityCollectionsQueue(Queue<IEntityCollection2> collectionsQueue)
{
base.GetFromMemberEntityCollectionsQueue(collectionsQueue);
}
/// <summary>Determines whether the entity has populated member collections</summary>
/// <returns>true if the entity has populated member collections.</returns>
protected override bool HasPopulatedMemberEntityCollections()
{
return base.HasPopulatedMemberEntityCollections();
}
/// <summary>Creates the member entity collections queue.</summary>
/// <param name="collectionsQueue">The collections queue.</param>
/// <param name="requiredQueue">The required queue.</param>
protected override void CreateMemberEntityCollectionsQueue(Queue<IEntityCollection2> collectionsQueue, Queue<bool> requiredQueue)
{
base.CreateMemberEntityCollectionsQueue(collectionsQueue, requiredQueue);
}
#endif
/// <summary>
/// Gets all related data objects, stored by name. The name is the field name mapped onto the relation for that particular data element.
/// </summary>
/// <returns>Dictionary with per name the related referenced data element, which can be an entity collection or an entity or null</returns>
public override Dictionary<string, object> GetRelatedData()
{
Dictionary<string, object> toReturn = new Dictionary<string, object>();
toReturn.Add("Company", _company);
toReturn.Add("Employee", _employee);
toReturn.Add("Paycode", _paycode);
return toReturn;
}
/// <summary> Adds the internals to the active context. </summary>
protected override void AddInternalsToContext()
{
if(_company!=null)
{
_company.ActiveContext = base.ActiveContext;
}
if(_employee!=null)
{
_employee.ActiveContext = base.ActiveContext;
}
if(_paycode!=null)
{
_paycode.ActiveContext = base.ActiveContext;
}
}
/// <summary> Initializes the class members</summary>
protected virtual void InitClassMembers()
{
_company = null;
_employee = null;
_paycode = null;
PerformDependencyInjection();
// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
// __LLBLGENPRO_USER_CODE_REGION_END
OnInitClassMembersComplete();
}
#region Custom Property Hashtable Setup
/// <summary> Initializes the hashtables for the entity type and entity field custom properties. </summary>
private static void SetupCustomPropertyHashtables()
{
_customProperties = new Dictionary<string, string>();
_fieldsCustomProperties = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> fieldHashtable = null;
fieldHashtable = new Dictionary<string, string>();
_fieldsCustomProperties.Add("CompanyId", fieldHashtable);
fieldHashtable = new Dictionary<string, string>();
_fieldsCustomProperties.Add("EmployeeId", fieldHashtable);
fieldHashtable = new Dictionary<string, string>();
_fieldsCustomProperties.Add("PaycodeId", fieldHashtable);
fieldHashtable = new Dictionary<string, string>();
_fieldsCustomProperties.Add("Amount", fieldHashtable);
fieldHashtable = new Dictionary<string, string>();
_fieldsCustomProperties.Add("ApplyDate", fieldHashtable);
fieldHashtable = new Dictionary<string, string>();
_fieldsCustomProperties.Add("NonWorkTimeId", fieldHashtable);
}
#endregion
/// <summary> Removes the sync logic for member _company</summary>
/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
private void DesetupSyncCompany(bool signalRelatedEntity, bool resetFKFields)
{
base.PerformDesetupSyncRelatedEntity( _company, new PropertyChangedEventHandler( OnCompanyPropertyChanged ), "Company", NonWorkTimeEntity.Relations.CompanyEntityUsingCompanyId, true, signalRelatedEntity, "NonWorkTime", resetFKFields, new int[] { (int)NonWorkTimeFieldIndex.CompanyId } );
_company = null;
}
/// <summary> setups the sync logic for member _company</summary>
/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
private void SetupSyncCompany(IEntity2 relatedEntity)
{
if(_company!=relatedEntity)
{
DesetupSyncCompany(true, true);
_company = (CompanyEntity)relatedEntity;
base.PerformSetupSyncRelatedEntity( _company, new PropertyChangedEventHandler( OnCompanyPropertyChanged ), "Company", NonWorkTimeEntity.Relations.CompanyEntityUsingCompanyId, true, new string[] { } );
}
}
/// <summary>Handles property change events of properties in a related entity.</summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCompanyPropertyChanged( object sender, PropertyChangedEventArgs e )
{
switch( e.PropertyName )
{
default:
break;
}
}
/// <summary> Removes the sync logic for member _employee</summary>
/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
private void DesetupSyncEmployee(bool signalRelatedEntity, bool resetFKFields)
{
base.PerformDesetupSyncRelatedEntity( _employee, new PropertyChangedEventHandler( OnEmployeePropertyChanged ), "Employee", NonWorkTimeEntity.Relations.EmployeeEntityUsingCompanyIdEmployeeId, true, signalRelatedEntity, "NonWorkTime", resetFKFields, new int[] { (int)NonWorkTimeFieldIndex.CompanyId, (int)NonWorkTimeFieldIndex.EmployeeId } );
_employee = null;
}
/// <summary> setups the sync logic for member _employee</summary>
/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
private void SetupSyncEmployee(IEntity2 relatedEntity)
{
if(_employee!=relatedEntity)
{
DesetupSyncEmployee(true, true);
_employee = (EmployeeEntity)relatedEntity;
base.PerformSetupSyncRelatedEntity( _employee, new PropertyChangedEventHandler( OnEmployeePropertyChanged ), "Employee", NonWorkTimeEntity.Relations.EmployeeEntityUsingCompanyIdEmployeeId, true, new string[] { } );
}
}
/// <summary>Handles property change events of properties in a related entity.</summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnEmployeePropertyChanged( object sender, PropertyChangedEventArgs e )
{
switch( e.PropertyName )
{
default:
break;
}
}
/// <summary> Removes the sync logic for member _paycode</summary>
/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
private void DesetupSyncPaycode(bool signalRelatedEntity, bool resetFKFields)
{
base.PerformDesetupSyncRelatedEntity( _paycode, new PropertyChangedEventHandler( OnPaycodePropertyChanged ), "Paycode", NonWorkTimeEntity.Relations.PaycodeEntityUsingCompanyIdPaycodeId, true, signalRelatedEntity, "NonWorkTime", resetFKFields, new int[] { (int)NonWorkTimeFieldIndex.CompanyId, (int)NonWorkTimeFieldIndex.PaycodeId } );
_paycode = null;
}
/// <summary> setups the sync logic for member _paycode</summary>
/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
private void SetupSyncPaycode(IEntity2 relatedEntity)
{
if(_paycode!=relatedEntity)
{
DesetupSyncPaycode(true, true);
_paycode = (PaycodeEntity)relatedEntity;
base.PerformSetupSyncRelatedEntity( _paycode, new PropertyChangedEventHandler( OnPaycodePropertyChanged ), "Paycode", NonWorkTimeEntity.Relations.PaycodeEntityUsingCompanyIdPaycodeId, true, new string[] { } );
}
}
/// <summary>Handles property change events of properties in a related entity.</summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnPaycodePropertyChanged( object sender, PropertyChangedEventArgs e )
{
switch( e.PropertyName )
{
default:
break;
}
}
/// <summary> Initializes the class with empty data, as if it is a new Entity.</summary>
/// <param name="validator">The validator object for this NonWorkTimeEntity</param>
/// <param name="fields">Fields of this entity</param>
protected virtual void InitClassEmpty(IValidator validator, IEntityFields2 fields)
{
OnInitializing();
base.Fields = fields;
base.IsNew=true;
base.Validator = validator;
InitClassMembers();
// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
// __LLBLGENPRO_USER_CODE_REGION_END
OnInitialized();
}
#region Class Property Declarations
/// <summary> The relations object holding all relations of this entity with other entity classes.</summary>
public static NonWorkTimeRelations Relations
{
get { return new NonWorkTimeRelations(); }
}
/// <summary> The custom properties for this entity type.</summary>
/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
public static Dictionary<string, string> CustomProperties
{
get { return _customProperties;}
}
/// <summary> Creates a new PrefetchPathElement2 object which contains all the information to prefetch the related entities of type 'Company'
/// for this entity. Add the object returned by this property to an existing PrefetchPath2 instance.</summary>
/// <returns>Ready to use IPrefetchPathElement2 implementation.</returns>
public static IPrefetchPathElement2 PrefetchPathCompany
{
get
{
return new PrefetchPathElement2(new EntityCollection(EntityFactoryCache2.GetEntityFactory(typeof(CompanyEntityFactory))),
(IEntityRelation)GetRelationsForField("Company")[0], (int)PayclockDAL.EntityType.NonWorkTimeEntity, (int)PayclockDAL.EntityType.CompanyEntity, 0, null, null, null, null, "Company", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
}
}
/// <summary> Creates a new PrefetchPathElement2 object which contains all the information to prefetch the related entities of type 'Employee'
/// for this entity. Add the object returned by this property to an existing PrefetchPath2 instance.</summary>
/// <returns>Ready to use IPrefetchPathElement2 implementation.</returns>
public static IPrefetchPathElement2 PrefetchPathEmployee
{
get
{
return new PrefetchPathElement2(new EntityCollection(EntityFactoryCache2.GetEntityFactory(typeof(EmployeeEntityFactory))),
(IEntityRelation)GetRelationsForField("Employee")[0], (int)PayclockDAL.EntityType.NonWorkTimeEntity, (int)PayclockDAL.EntityType.EmployeeEntity, 0, null, null, null, null, "Employee", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
}
}
/// <summary> Creates a new PrefetchPathElement2 object which contains all the information to prefetch the related entities of type 'Paycode'
/// for this entity. Add the object returned by this property to an existing PrefetchPath2 instance.</summary>
/// <returns>Ready to use IPrefetchPathElement2 implementation.</returns>
public static IPrefetchPathElement2 PrefetchPathPaycode
{
get
{
return new PrefetchPathElement2(new EntityCollection(EntityFactoryCache2.GetEntityFactory(typeof(PaycodeEntityFactory))),
(IEntityRelation)GetRelationsForField("Paycode")[0], (int)PayclockDAL.EntityType.NonWorkTimeEntity, (int)PayclockDAL.EntityType.PaycodeEntity, 0, null, null, null, null, "Paycode", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
}
}
/// <summary> The custom properties for the type of this entity instance.</summary>
/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
[Browsable(false), XmlIgnore]
public override Dictionary<string, string> CustomPropertiesOfType
{
get { return NonWorkTimeEntity.CustomProperties;}
}
/// <summary> The custom properties for the fields of this entity type. The returned Hashtable contains per fieldname a hashtable of name-value
/// pairs. </summary>
/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
public static Dictionary<string, Dictionary<string, string>> FieldsCustomProperties
{
get { return _fieldsCustomProperties;}
}
/// <summary> The custom properties for the fields of the type of this entity instance. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
[Browsable(false), XmlIgnore]
public override Dictionary<string, Dictionary<string, string>> FieldsCustomPropertiesOfType
{
get { return NonWorkTimeEntity.FieldsCustomProperties;}
}
/// <summary> The CompanyId property of the Entity NonWorkTime<br/><br/>
/// </summary>
/// <remarks>Mapped on table field: "NonWorkTime"."CompanyId"<br/>
/// Table field type characteristics (type, precision, scale, length): Integer, 10, 0, 4<br/>
/// Table field behavior characteristics (is nullable, is PK, is identity): false, true, false</remarks>
public virtual System.Int32 CompanyId
{
get { return (System.Int32)GetValue((int)NonWorkTimeFieldIndex.CompanyId, true); }
set { SetValue((int)NonWorkTimeFieldIndex.CompanyId, value); }
}
/// <summary> The EmployeeId property of the Entity NonWorkTime<br/><br/>
/// </summary>
/// <remarks>Mapped on table field: "NonWorkTime"."EmployeeId"<br/>
/// Table field type characteristics (type, precision, scale, length): Integer, 10, 0, 4<br/>
/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
public virtual System.Int32 EmployeeId
{
get { return (System.Int32)GetValue((int)NonWorkTimeFieldIndex.EmployeeId, true); }
set { SetValue((int)NonWorkTimeFieldIndex.EmployeeId, value); }
}
/// <summary> The PaycodeId property of the Entity NonWorkTime<br/><br/>
/// </summary>
/// <remarks>Mapped on table field: "NonWorkTime"."PaycodeId"<br/>
/// Table field type characteristics (type, precision, scale, length): Integer, 10, 0, 4<br/>
/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
public virtual System.Int32 PaycodeId
{
get { return (System.Int32)GetValue((int)NonWorkTimeFieldIndex.PaycodeId, true); }
set { SetValue((int)NonWorkTimeFieldIndex.PaycodeId, value); }
}
/// <summary> The Amount property of the Entity NonWorkTime<br/><br/>
/// </summary>
/// <remarks>Mapped on table field: "NonWorkTime"."Amount"<br/>
/// Table field type characteristics (type, precision, scale, length): BigInt, 20, 0, 8<br/>
/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
public virtual System.TimeSpan Amount
{
get { return (System.TimeSpan)GetValue((int)NonWorkTimeFieldIndex.Amount, true); }
set { SetValue((int)NonWorkTimeFieldIndex.Amount, value); }
}
/// <summary> The ApplyDate property of the Entity NonWorkTime<br/><br/>
/// </summary>
/// <remarks>Mapped on table field: "NonWorkTime"."ApplyDate"<br/>
/// Table field type characteristics (type, precision, scale, length): TimeStamp, 0, 0, 8<br/>
/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
public virtual System.DateTime ApplyDate
{
get { return (System.DateTime)GetValue((int)NonWorkTimeFieldIndex.ApplyDate, true); }
set { SetValue((int)NonWorkTimeFieldIndex.ApplyDate, value); }
}
/// <summary> The NonWorkTimeId property of the Entity NonWorkTime<br/><br/>
/// </summary>
/// <remarks>Mapped on table field: "NonWorkTime"."NonWorkTimeId"<br/>
/// Table field type characteristics (type, precision, scale, length): Integer, 10, 0, 4<br/>
/// Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
public virtual System.Int32 NonWorkTimeId
{
get { return (System.Int32)GetValue((int)NonWorkTimeFieldIndex.NonWorkTimeId, true); }
set { SetValue((int)NonWorkTimeFieldIndex.NonWorkTimeId, value); }
}
/// <summary> Gets / sets related entity of type 'CompanyEntity' which has to be set using a fetch action earlier. If no related entity
/// is set for this property, null is returned. This property is not visible in databound grids.</summary>
[Browsable(false)]
public virtual CompanyEntity Company
{
get
{
return _company;
}
set
{
if(base.IsDeserializing)
{
SetupSyncCompany(value);
}
else
{
if(value==null)
{
if(_company != null)
{
_company.UnsetRelatedEntity(this, "NonWorkTime");
}
}
else
{
if(_company!=value)
{
((IEntity2)value).SetRelatedEntity(this, "NonWorkTime");
}
}
}
}
}
/// <summary> Gets / sets related entity of type 'EmployeeEntity' which has to be set using a fetch action earlier. If no related entity
/// is set for this property, null is returned. This property is not visible in databound grids.</summary>
[Browsable(false)]
public virtual EmployeeEntity Employee
{
get
{
return _employee;
}
set
{
if(base.IsDeserializing)
{
SetupSyncEmployee(value);
}
else
{
if(value==null)
{
if(_employee != null)
{
_employee.UnsetRelatedEntity(this, "NonWorkTime");
}
}
else
{
if(_employee!=value)
{
((IEntity2)value).SetRelatedEntity(this, "NonWorkTime");
}
}
}
}
}
/// <summary> Gets / sets related entity of type 'PaycodeEntity' which has to be set using a fetch action earlier. If no related entity
/// is set for this property, null is returned. This property is not visible in databound grids.</summary>
[Browsable(false)]
public virtual PaycodeEntity Paycode
{
get
{
return _paycode;
}
set
{
if(base.IsDeserializing)
{
SetupSyncPaycode(value);
}
else
{
if(value==null)
{
if(_paycode != null)
{
_paycode.UnsetRelatedEntity(this, "NonWorkTime");
}
}
else
{
if(_paycode!=value)
{
((IEntity2)value).SetRelatedEntity(this, "NonWorkTime");
}
}
}
}
}
/// <summary> Gets the type of the hierarchy this entity is in. </summary>
protected override InheritanceHierarchyType LLBLGenProIsInHierarchyOfType
{
get { return InheritanceHierarchyType.None;}
}
/// <summary> Gets or sets a value indicating whether this entity is a subtype</summary>
protected override bool LLBLGenProIsSubType
{
get { return false;}
}
/// <summary>Returns the PayclockDAL.EntityType enum value for this entity.</summary>
[Browsable(false), XmlIgnore]
public override int LLBLGenProEntityTypeValue
{
get { return (int)PayclockDAL.EntityType.NonWorkTimeEntity; }
}
#endregion
#region Custom Entity code
// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
public override bool Equals(object obj)
{
bool result = false;
NonWorkTimeEntity passedIn = obj as NonWorkTimeEntity;
if (passedIn != null)
{
result = (this.NonWorkTimeId == passedIn.NonWorkTimeId);
}
return result;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
// __LLBLGENPRO_USER_CODE_REGION_END
#endregion
#region Included code
#endregion
}
}
Hi pszlachetka,
If you don't specify values for some fields, they are not included in the INSERT query. Please take a look at this quote from the Manual:
Manual wrote:
Some datatypes, like date related datatypes and strings, are not always mandatory and are set to an unknown value. In most cases this is NULL: the fields in the table are nullable and, if these fields do not yet have a value, they're set to NULL. Nullable fields often have a 'default' value set; this is a value which is inserted by the database server when a NULL is inserted in such a column. These default values are defined in the table definition itself.
Please take a look at the code when you are inserting the entity, maybe you are not setting the values for those fields.
For more information please read Entities, Defaults and NULL values and defaults.
PS. Next time please post only relevant code, or attach the file
Joined: 03-Sep-2009
I have verified that the entity has values for all five required fields. I have also made sure that the values do not violate any referential integrity in the database.
Joined: 03-Sep-2009
Simple test does work. What's strange is that I'm saving an EmployeeEntity, which has a Collection of NonWorkTimeEntities hanging off it. Right before the save, I check the collection and it only contains a single NonWorkTimeEntity. The NonWorkTimeEntity has another entity hanging off it, and I believe there might be some other NonWorkTimeEntities hanging off it that are being saved before the one in the collection I'm looking at.