Hello Interface using in another project interface and hasn't implementation Query.All<interface> throw exception

Interface

public interface IMyInterface : IEntity
{
    [Key]
    [Field(Nullable = false)]
    Guid Id { get; set; }

    [Field]
    string Name { get; set; }
}

Next code throw exception

public static class Program
{
    static void Main(string[] args)
    {
        var dc = new DomainConfiguration("sqlserver://localhost/DO40-Tests");
        dc.Types.Register(typeof(IMyInterface));
        dc.UpgradeMode = DomainUpgradeMode.Recreate;

        using (var domain = Domain.Build(dc))
        {
            using (var s = domain.OpenSession())
            {
                using (s.Activate())
                {
                    using (s.OpenTransaction())
                    {
                        s.Query.All<IMyInterface>().ToArray();
                    }
                }
            }
        }
    }
}

"Unable to translate 'Query.All()' expression. See inner exception for details."
"Type 'ConsoleApplication1.IMyInterface' is not found in model."

After register implementation, no more errors

[HierarchyRoot]
public class Ent : Entity, IMyInterface
{
    public Guid Id { get; set; }

    public string Name { get; set; }
}

public static class Program
{
    static void Main(string[] args)
    {
        var dc = new DomainConfiguration("sqlserver://localhost/DO40-Tests");
        dc.Types.Register(typeof(IMyInterface));
        dc.Types.Register(typeof(Ent));
        dc.UpgradeMode = DomainUpgradeMode.Recreate;

        using (var domain = Domain.Build(dc))
        {
            using (var s = domain.OpenSession())
            {
                using (s.Activate())
                {
                    using (s.OpenTransaction())
                    {
                        s.Query.All<IMyInterface>().ToArray();
                    }
                }
            }
        }
    }
}

Maybe should return empty result instead exception

DO 4.6.6

asked May 26 '14 at 06:45

Anton%20Guschin's gravatar image

Anton Guschin
73243035


One Answer:

Hello Anton,

currently we don't fully support persistent interfaces without implementation.

If interface is defined but there are no implementors DataObjects.Net will either silently drop interface from model or throw an exception during Domain.Build depending on occurrence of persistent fields of this interface.

It seems that you've encountered first case: interface is not registered in the model because it was dropped.

answered May 26 '14 at 06:51

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

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