Open john-warpdevelopment opened 8 years ago
Hmm, might it be that the Address is null? Complex types most likely has to be initiated (like when you save with EF the normal way)
I did try instantiating the complex types, didn't help here is the complete model:
public partial class Person : BaseEntity
{
#region Constructor
public Person()
{
this.CreatedOnUtc = DateTime.Now;
this.ModifiedOnUtc = DateTime.Now;
this.Gender = Common.Gender.Male;
this.PersonGuid = Guid.NewGuid();
this.PersonStatus = PersonStatus.Enabled;
this.Memberships = new HashSet<Member>();
this.Leads = new HashSet<Lead>();
this.LeadComments = new HashSet<LeadComment>();
this.LeadAssigns = new HashSet<LeadAssign>();
this.LeaveRequests = new HashSet<Leave>();
this.LeaveApprovals = new HashSet<Leave>();
this.Assets = new HashSet<Asset>();
this.ContactDetails = new HashSet<ContactDetail>();
this.Accounts = new HashSet<Account>();
this.Documents = new HashSet<Document>();
}
#endregion
#region Value Properties
public Int32 PersonId { get; set; }
public Nullable<int> AddressId { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime ModifiedOnUtc { get; set; }
public Guid PersonGuid { get; set; }
public String Title { get; set; }
public String FirstName { get; set; }
public String MiddleNames { get; set; }
public String Surname { get; set; }
public String Alias { get; set; }
public Nullable<System.DateTime> Birthday { get; set; }
public String Email { get; set; }
internal string GenderEnum { get; set; }
internal string PersonStatusEnum { get; set; }
public String PasswordSalt { get; set; }
public String Password { get; set; }
public String Tag { get; set; }
public string IdNumber { get; set; }
public string AccountNumber { get; set; }
#endregion
#region Enumeration Properties
public Gender Gender
{
get { return (Gender)Enum.Parse(typeof(Gender), this.GenderEnum); }
set { this.GenderEnum = value.ToString(); }
}
public PersonStatus PersonStatus
{
get { return (PersonStatus)Enum.Parse(typeof(PersonStatus), this.PersonStatusEnum); }
set { this.PersonStatusEnum = value.ToString(); }
}
#endregion
#region Navigation Properties
public ICollection<Member> Memberships { get; set; }
public ICollection<Lead> Leads { get; set; }
public ICollection<LeadComment> LeadComments { get; set; }
public ICollection<LeadAssign> LeadAssigns { get; set; }
public Address Address { get; set; }
public ICollection<Leave> LeaveApprovals { get; set; }
public ICollection<Leave> LeaveRequests { get; set; }
public ICollection<Asset> Assets { get; set; }
public PersonLeaveInfo PersonLeaveInfo { get; set; }
public ICollection<ContactDetail> ContactDetails { get; set; }
public ICollection<Account> Accounts { get; set; }
public ICollection<Document> Documents { get; set; }
#endregion
}
what's weird is it worked for some of my other entities that have complex types , and enumerations same as this one.
I might need to debug this one. Did the types it work for have the same base class?
If they did I suspect the internal properties but I'll have to try it.
Yes , that base class is empty it's just used for generics.
I had the same problem. My object has only primitive properties (date, string and int) and my table accepts NULL on all of them. Any clue what could be causing this ?
This is my exception:
2016-06-03 12:13:12,633 [8] ERROR [Controllers.LogsController+2.Insert(TKey key, TValue value, Boolean add) at EntityFramework.Utilities.EfMappingFactory.GetMappingsForContext(DbContext context) at EntityFramework.Utilities.EFBatchOperation
2.InsertAll[TEntity](IEnumerable1 items, DbConnection connection, Nullable
1 batchSize)
at WRE.George.API.Controllers.LogsController.
I'm using EF 6 Code First, and when I try and inserting +-1000 I'm getting the error "Object reference not set to an instance of an object.". Wonder if the issue is with handeling optional collumns.
e.g. the following model
Here is a stack trace:
at EntityFramework.Utilities.EFDataReader
1.<.ctor>b__1(ColumnMapping p) at System.Linq.Enumerable.WhereSelectListIterator
2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable
1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at EntityFramework.Utilities.EFDataReader
1..ctor(IEnumerable1 items, IEnumerable
1 properties) at EntityFramework.Utilities.SqlQueryProvider.InsertItems[T](IEnumerable1 items, String schema, String tableName, IList
1 properties, DbConnection storeConnection, Nullable1 batchSize) at EntityFramework.Utilities.EFBatchOperation
2.InsertAll[TEntity](IEnumerable1 items, DbConnection connection, Nullable
1 batchSize)