コード例 #1
0
        public void Delegate_setter_is_cached_by_type_and_property_name()
        {
            var entityType = new EntityType(typeof(Customer));
            var idProperty = entityType.AddProperty("Id", typeof(int));

            var source = new ClrPropertySetterSource();

            var accessor = source.GetAccessor(typeof(Customer), "Id");

            Assert.Same(accessor, source.GetAccessor(typeof(Customer), "Id"));
            Assert.Same(accessor, source.GetAccessor(idProperty));
        }
コード例 #2
0
        public void Property_is_returned_if_it_implements_IClrPropertySetter()
        {
            var setterMock   = new Mock <IClrPropertySetter>();
            var propertyMock = setterMock.As <IProperty>();

            var source = new ClrPropertySetterSource();

            Assert.Same(setterMock.Object, source.GetAccessor(propertyMock.Object));
        }
コード例 #3
0
        private NavigationAccessor Create(INavigation navigation)
        {
            var elementType = navigation.EntityType.Type.GetAnyProperty(navigation.Name).PropertyType.TryGetElementType(typeof(IEnumerable <>));

            var targetType = navigation.PointsToPrincipal
                ? navigation.ForeignKey.ReferencedEntityType
                : navigation.ForeignKey.EntityType;

            // TODO: Consider allowing an annotation to force treating a reference to an Entity which is an IEnumerable of
            // itself as a reference instead of a collection. Currently it will be considered a collection nav prop, which it isn't.

            return(elementType != null && elementType == targetType.Type
                ? new CollectionNavigationAccessor(
                       () => _getterSource.GetAccessor(navigation),
                       () => _setterSource.GetAccessor(navigation),
                       () => _collectionAccessorSource.GetAccessor(navigation))
                : new NavigationAccessor(
                       () => _getterSource.GetAccessor(navigation),
                       () => _setterSource.GetAccessor(navigation)));
        }