This project has moved. For the latest updates, please go here.
1

Closed

Patch to avoid a nullreference exception

description

I recommand two modifications :

DbContext.ToDataTable.cs:241
 foreach (ConceptualNavigationProperty navProperty in entity.NavigationProperties)
            {
                var navEntity = type.GetProperty(navProperty.Name).GetValue(item, null);
                var navEntityType = type.GetProperty(navProperty.Name).PropertyType;
                //navEntity can be null !
                foreach (var propertyMapping in navProperty.Mappings)
                {
                    var property = navEntityType.GetProperty(propertyMapping.Item1); 
                    dt.Columns[propertyMapping.Item2.Name].DataType = property.PropertyType;
                }
            }
DbContext.ToDataTable.cs:
 foreach (ConceptualNavigationProperty navProperty in entity.NavigationProperties)
            {
                var navEntity = type.GetProperty(navProperty.Name).GetValue(item, null);
                //navEntity can be null !
                foreach (var propertyMapping in navProperty.Mappings)
                {
                    if (navEntity == null)
                    {
                        dr[propertyMapping.Item2.Name] = DBNull.Value;
                        continue;
                    }

                    var property = navEntity.GetType().GetProperty(propertyMapping.Item1);
                    object value = property.GetValue(navEntity, null);
                    dr[propertyMapping.Item2.Name] = value ?? DBNull.Value;
                }
            }
Closed Nov 23, 2014 at 11:13 PM by Jonathan_Magnan
Should have been closed 6 month ago!

comments

Jonathan_Magnan wrote Jul 9, 2014 at 4:31 PM

Thank you for your solution.

A major release is planned for this project (including your change) on July 21,

You can find the roadmap here: https://zentityframework.codeplex.com/discussions/550951

wrote Nov 23, 2014 at 11:13 PM