[HierarchyRoot]
public class Login2Partner : Entity
{
    public Login2Partner(Session session) : base(session)
    {
    }

    [Key]
    [Field]
    public Guid ID { get; private set; }

    [Field(Indexed = true)]
    [PastConstraint]
    public DateTime Inserted { get; set; }

    [Field(Nullable = false)]
    public Login Login { get; set; }

    [Field(Indexed = true, Nullable = false)]
    [NotNullOrEmptyConstraint]
    public string Partner { get; set; }

    [Field(Indexed = true, Nullable = false)]
    [NotNullOrEmptyConstraint]
    public string Key { get; set; }

    [Field(Nullable = true, Indexed = true)]
    public string Campaign { get; set; }
}

throw exception on validate:

System.InvalidOperationException: Can not commit a transaction. Entities validation failed. ---> Xtensive.Core.AggregateException: Validation failed. ---> Xtensive.Core.AggregateException: A set of exceptions is caught. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.AmbiguousMatchException: Ambiguous match found.

at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) at System.Type.GetProperty(String name) at Xtensive.Reflection.DelegateHelper.InnerCreateGetMemberDelegateTObject,TValue,TDelegateType at Xtensive.Reflection.DelegateHelper.CreateGetMemberDelegateTObject,TValue at Xtensive.Orm.Validation.PropertyConstraintAspect.GetPropertyGetterTOwner,TProperty --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Xtensive.Orm.Validation.PropertyConstraintAspect.<getpropertyvalue>b__1(PropertyConstraintAspect _this) at Xtensive.Threading.ThreadSafeCached1.GetValue[T1](Func2 generator, T1 argument) at Xtensive.Orm.Validation.PropertyConstraintAspect.GetPropertyValue(IValidationAware target) at Xtensive.Orm.Validation.PropertyConstraintAspect.Check(IValidationAware target) at Xtensive.Core.ExceptionAggregator.ExecuteT --- End of inner exception stack trace --- at Xtensive.Core.ExceptionAggregator.Dispose() at Xtensive.Orm.Validation.ValidationAwareExtensions.CheckConstraints(IValidationAware target) at Xtensive.Orm.Persistent.InnerOnValidate() at Xtensive.Orm.Persistent.Xtensive.Orm.Validation.IValidationAware.OnValidate() at Xtensive.Orm.Validation.ValidationContext.Validate() --- End of inner exception stack trace --- at Xtensive.Orm.Validation.ValidationContext.Validate() at Xtensive.Orm.Transaction.CompleteValidation() --- End of inner exception stack trace --- at Xtensive.Orm.Transaction.CompleteValidation() at Xtensive.Orm.Transaction.Commit() at Xtensive.Orm.TransactionScope.Dispose() ...

asked Jul 27 '11 at 11:14

proff's gravatar image

proff
75336


One Answer:

Hello proff,

That happens because Entity class already has Key property declared. Try renaming Login2Partner.Key one. The same goes for State property as well.

answered Jul 27 '11 at 11:22

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Already commented constraint. It's bug report, not question

(Jul 27 '11 at 11:27) proff proff's gravatar image

Sorry this happens.

But the problem is that both classes have the same property Key which in turn cause AmbiguousMatchException to be thrown. The practice to give properties equal names in the same class is not considered as good and the compiler should have warned about it.

The solution is to rename Login2Partner.Key to something that differs from Key name. Please, take Key name as a reserved word.

(Jul 27 '11 at 12:04) Dmitri Maximov Dmitri%20Maximov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA