문제

I'm trying to add business logic to my database first entity framework appplication. I want to limit the length of address1 to 35 and move the rest to address to. In the database the fields are Address1 and Address2, on my edmx it is address1 and address2. I extened the edmx using a partial. but when ever trying to call my custom get function I get an exception saying the current thread is in a stackoverflow.

 public partial class EmployeeWithAddress
    {
        public string Address1
        {
            get
            {
                var employee = Common.LimitAddressFieldTo35(this);
                address1 = employee.Address1;
                address2 = employee.Address2;
                return address1;
            }
            set { address1 = value; }
        }

        public string Address2 { get; set; }
    }

static public EmployeeWithAddress LimitAddressFieldTo35(EmployeeWithAddress employee)
        {
            var ee = employee;  
            if (ee.Address1.Length > 35)
            {
                var address = ee.Address1;
                ee.Address1 = address.Substring(0, 35).Trim();
                ee.Address2 =
                    string.Concat(address.Substring(35, address.Length - 35) + " ", employee.Address2).Trim();
            }

            return ee;
        }

the exception occurs when calling LimitAddressFieldTo35. I am using the entity framework version included in .net 3.5

도움이 되었습니까?

해결책

This is going to recurse infinitely

Address1 { get { ... address1 = employee.Address1; ...} }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top