Skip to content

Commit

Permalink
fix binding readonly properties (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio authored Aug 28, 2023
1 parent e4b4e54 commit 2bde4e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private static Expression RemoveNonStructucalProperties(QueryBinderContext conte
{
foreach (var sp in structuralProperties)
{
if (model.GetClrPropertyName(sp) == prop.Name)
if (prop.CanWrite && model.GetClrPropertyName(sp) == prop.Name)
{
MemberExpression propertyExpression = Expression.Property(source, prop);
bindings.Add(Expression.Bind(prop, propertyExpression));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;
Expand Down Expand Up @@ -295,6 +296,10 @@ public void Bind_UsingEFQueryProvider_GeneratedExpression__DoesNot_ContainExpand
SelectExpandWrapper<QueryCustomer> innerInnerCustomer = Assert.IsAssignableFrom<SelectExpandWrapper<QueryCustomer>>(customer);

Assert.Null(innerInnerCustomer.Instance.Orders);
Assert.Equal(2, innerInnerCustomer.Instance.TestReadonlyProperty.Count);
Assert.Equal("Test1", innerInnerCustomer.Instance.TestReadonlyProperty[0]);
Assert.Equal("Test2", innerInnerCustomer.Instance.TestReadonlyProperty[1]);
Assert.Equal(2, innerInnerCustomer.Instance.TestReadOnlyWithAttribute);
}

[Theory]
Expand Down Expand Up @@ -2228,6 +2233,26 @@ public class QueryCustomer

public IList<QueryOrder> Orders { get; set; }

public List<string> TestReadonlyProperty
{
get { return new List<string>() { "Test1", "Test2" }; }
}

[ReadOnly(true)]
public int TestReadOnlyWithAttribute
{
get
{
return 2;
}
}

[ReadOnly(true)]
public int TestReadOnlyWithAttributeAndSetter
{
get; set;
}

public IDictionary<string, object> CustomerProperties { get; set; }
}

Expand Down

0 comments on commit 2bde4e5

Please sign in to comment.