Example (DO 5.0.18)

using System;
using System.Linq;

using Xtensive.Orm;
using Xtensive.Orm.Configuration;

using Domain = Xtensive.Orm.Domain;

class Program
{
    static void Main(string[] args)
    {
        var dc = new DomainConfiguration("sqlserver://localhost/DO40-Tests");

        dc.Types.Register(typeof(IWithStatus));
        dc.Types.Register(typeof(TestEntity));
        dc.Types.Register(typeof(Status));

        dc.UpgradeMode = DomainUpgradeMode.Recreate;
        var sessionConfiguration = new SessionConfiguration(SessionOptions.AutoActivation | SessionOptions.ServerProfile);

        using (var domain = Domain.Build(dc))
        {
            using (var session = domain.OpenSession(sessionConfiguration))
            using (session.Activate())
            using (var t = session.OpenTransaction())
            {
                var status = new Status { Name = "test" };
                new TestEntity { TestField = "Test", Status = status };

                t.Complete();
            }

            using (var session = domain.OpenSession(sessionConfiguration))
            using (session.Activate())
            using (var t = session.OpenTransaction())
            {
                Query.All<TestEntity>()
                    .OfType<IWithStatus>()
                    .Select(e => e.Status)
                    .Any(); // OK

                Query.All<TestEntity>()
                    .OfType<IWithStatus>()
                    .Select(e => e.Status)
                    .ToArray(); // Exception
            }
        }
    }
}

public interface IWithStatus : IEntity
{
    [Field]
    Status Status { get; set; }
}

[HierarchyRoot]
[Serializable]
public partial class Status : Entity
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    [Field]
    public bool IsDeletable { get; set; }

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

[HierarchyRoot]
[Serializable]
public class TestEntity : Entity, IWithStatus
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    [Field]
    public string TestField { get; set; }

    public Status Status { get; set; }
}

Exception

Unhandled Exception: Xtensive.Orm.StorageException: SQL error occured.
SQL error details 'Type: Unknown;'
Query 'SELECT DISTINCT [a].[Id] AS [#a.Id], 100 AS [#a.TypeId], [a].[IsDeletable] AS [#a.IsDeletable], [a].[Name] AS [#a.Name] FROM [dbo].[TestEntity] [b] LEFT OUTER JOIN [dbo].[Status] [a] ON ([b].[TestField] = [a].[Id]) WHERE (NOT ([a].[IsDeletable] <> 0));
'
Original message 'Conversion failed when converting from a character string to uniqueidentifier.' ---> System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
   at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
   at System.Data.SqlClient.SqlDataReader.Read()
   at Xtensive.Orm.Providers.Command.NextRow()
   --- End of inner exception stack trace ---
   at Xtensive.Orm.Providers.Command.NextRow()
   at Xtensive.Orm.Providers.Command.<AsReaderOf>d__0.MoveNext()
   at Xtensive.Orm.Providers.SqlSessionHandler.<Xtensive.Orm.Providers.IProviderExecutor.ExecuteTupleReader>d__2.MoveNext()
   at Xtensive.Orm.Providers.SqlProvider.<OnEnumerate>d__9.MoveNext()
   at Xtensive.Orm.Rse.Providers.ExecutableProvider.<GetEnumerator>d__0.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Xtensive.Orm.Rse.RecordSet.<GetGreedyEnumerator>d__0.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Xtensive.Core.EnumerableExtensions.<Batch>d__e`1.MoveNext()
   at Xtensive.Core.EnumerableExtensions.<ApplyBeforeAndAfter>d__16`1.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Sample.Program.Main(String[] args) in C:\Projects\CleanDO\Sample\Program.cs:line 40

asked Feb 07 at 00:01

Gushchin%20Anton's gravatar image

Gushchin Anton
9121921


One Answer:

Hello Anton,

Thank you for the report. It seems to be one of the cases for know issue with .OfType<t>() translation. We're working on that.

answered Feb 07 at 05:44

Alexey%20Kulakov's gravatar image

Alexey Kulakov
73215

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