It can be reproduced on 7524 build, on 7487 everything is ok.

We have:


[Serializable]
    [HierarchyRoot(InheritanceSchema = InheritanceSchema.ConcreteTable)]
    public abstract class BaseEntity : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

    [Field(Nullable = false)]
    public int IdSection { get; private set; }

    [Field]
    public int Num { get; set; }

   [Field]
    public File File1 { get; set; }

    protected BaseEntity(int idSection, string nameAdmin)
    {
        NameAdmin = nameAdmin;
        IdSection = idSection;
    }
}

[Serializable] public class File : Structure { [Field] public string FileName { get; set; }

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

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

    public string AbsolutePath
    {
        get { return "/" + RelativePath; }
    }
}

public class CommonPage : BaseEntity { public CommonPage(int idSection, string nameAdmin) : base(idSection, nameAdmin) { }

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

    [Field]
    public File CustomFile { get; set; }

    [Field]
    public File11 CustomFile11 { get; set; }

       }

[Serializable] public class File11 : Structure { [Field] public string X { get; set; } }

/ and some code with Structure - null /

var t = Xtensive.Orm.Session.Current.Query.All<commonpage>().FirstOrDefault(z => z.Id == 36);

        var t2 = t.CustomFile; // null
        var t3 = t.File1; // not NULL
        var t4 = t.CustomFile11; //null

BaseEntity and File located in one assembly, and CommonPage and File1 - in another.

So, File field in base class works ok, but in child class - it has Null value.

Update: Seems, problem is in different assemblies. Even int or string fields can't be saved.

So, here is case: we have base abstract entity class in one assembly, and child concrete class in another assembly.

When trying to read fields of child class we got NULL instead of field values, even if there are some values in database.

And field values exists only in Session/Transaction, and not stored in database.

Genereated code from Reflector: base class, one assembly

[Serializable, Initializable(AttributeId=-5123476168254685180L, AttributePriority=0x20000000), Display(ChildEntitiesDisplayMode=ChildEntitiesDisplayMode.Entities), HierarchyRoot(InheritanceSchema=2), HasInheritedAttribute(new long[] { -5123476168254685177L })]
public abstract class BaseEntity : Entity
{
    // Fields
    private List<type> _hierarchy;
    private readonly List<pagetemplate> _pageTemplates;

// Methods
[CompilerGenerated]
protected BaseEntity(EntityState arg0);
protected BaseEntity(int idSection, string nameAdmin);
[CompilerGenerated]
protected BaseEntity(SerializationInfo arg0, StreamingContext arg1);
[CompilerGenerated]
protected BaseEntity(Session arg0, EntityState arg1);

............. public DisplayAttribute GetDisplaySettings(); private void GetHierarchy(BaseEntity entity);

// Properties
public IEnumerable<BaseEntity> ChildEntities { get; }
[Field]
private EntitySet<BaseEntity> ChildEntitySet { [CompilerGenerated, CompilerGenerated, DebuggerNonUserCode] get; [CompilerGenerated, DebuggerNonUserCode, CompilerGenerated] set; }
[Field]
public File File1 { [DebuggerNonUserCode, CompilerGenerated, CompilerGenerated] get; [DebuggerNonUserCode, CompilerGenerated, CompilerGenerated] set; }
public IEnumerable<Type> Hierarchy { get; }
[Field, Key]
public int Id { [CompilerGenerated, DebuggerNonUserCode, CompilerGenerated] get; [CompilerGenerated, CompilerGenerated, DebuggerNonUserCode] private set; }
[Field(Nullable=false)]
public int IdSection { [CompilerGenerated, CompilerGenerated, DebuggerNonUserCode] get; [DebuggerNonUserCode, CompilerGenerated, CompilerGenerated] private set; }
[ModelField(Label="Главная страница шаблона", ModelFieldType=ModelFieldType.Checkbox, PropertyName="IsMainInSection", ValueType=typeof(bool), Group=Group.Core), Field]
public bool IsMainInSection { [CompilerGenerated, CompilerGenerated, DebuggerNonUserCode] get; [CompilerGenerated, DebuggerNonUserCode, CompilerGenerated] set; }
[Field, ModelField(Label="Видима", ModelFieldType=ModelFieldType.Checkbox, PropertyName="IsVisible", ValueType=typeof(bool), Group=Group.Core)]
public bool IsVisible { [CompilerGenerated, CompilerGenerated, DebuggerNonUserCode] get; [CompilerGenerated, CompilerGenerated, DebuggerNonUserCode] set; }
[Field]
public int ListItemTemplateId { [DebuggerNonUserCode, CompilerGenerated, CompilerGenerated] get; [CompilerGenerated, DebuggerNonUserCode, CompilerGenerated] set; }
[Field]
public int ListTemplateId { [CompilerGenerated, CompilerGenerated, DebuggerNonUserCode] get; [CompilerGenerated, DebuggerNonUserCode, CompilerGenerated] set; }

......................

// Nested Types
[DebuggerNonUserCode, CompilerGenerated]
internal sealed class <>z__Aspects
{
    // Fields
    internal static Type _1;
    internal static LocationInfo _10;
    internal static LocationInfo _11;
    internal static LocationInfo _12;
    internal static LocationInfo _13;
    internal static LocationInfo _14;
    ..............
    // Methods
    [CompilerGenerated]
    static <>z__Aspects();
}

}

Code from child file (another assembly)


[Initializable(AttributeId=-5123476168254685180L, AttributePriority=0x30000000), HasInheritedAttribute(new long[] { -5123476168254685177L })]
public class CommonPage : BaseEntity
{
    // Methods
    [CompilerGenerated]
    protected CommonPage(EntityState arg0);
    public CommonPage(int idSection, string nameAdmin);
    [CompilerGenerated]
    protected CommonPage(SerializationInfo arg0, StreamingContext arg1);
    [CompilerGenerated]
    protected CommonPage(Session arg0, EntityState arg1);
    [DebuggerNonUserCode, CompilerGenerated]
    private static CommonPage ~Xtensive.Aspects.FactoryMethod(EntityState arg0);
    [DebuggerNonUserCode, CompilerGenerated]
    private static CommonPage ~Xtensive.Aspects.FactoryMethod(SerializationInfo arg0, StreamingContext arg1);
    [DebuggerNonUserCode, CompilerGenerated]
    private static CommonPage ~Xtensive.Aspects.FactoryMethod(Session arg0, EntityState arg1);

// Properties
[ModelField(Label="Файл", ModelFieldType=ModelFieldType.File, PropertyName="CustomFile", Group=Group.Specific), Field]
public File CustomFile { get; set; }
[Field, Preview(Quality=10), ModelField(Label="Картинка", ModelFieldType=ModelFieldType.File, PropertyName="CustomPhoto", Group=Group.Specific), Preview(Width=300, Heigth=300, Quality=50, FolderName="p2")]
public Photo CustomPhoto { get; set; }
[ModelField(Label="H1", PropertyName="H1", Group=Group.Specific), Field]
public string H1 { get; set; }

// Nested Types
[DebuggerNonUserCode, CompilerGenerated]
internal sealed class <>z__Aspects
{
    // Fields
    internal static Type _1;

    // Methods
    [CompilerGenerated]
    static <>z__Aspects();
}

}

So, assembly with child class have been processed correctly, but fields have not been processed.

asked Jun 06 '11 at 05:57

Ness's gravatar image

Ness
155232328

edited Jun 06 '11 at 10:15

Ness, thanks for the code sample. I'll check this right after the issue with SQL Server CE

(Jun 06 '11 at 07:19) Dmitri Maximov Dmitri%20Maximov's gravatar image

Problem is in different assemblies. Even int or string fields can't be saved.

So, here is case: we have base abstract entity class in one assembly, and child concrete class in another assembly.

When trying to read fields of child class we got NULL instead of field values, even if there are some values in database.

And field values exists only in Session/Transaction, and not stored in database.

(Jun 06 '11 at 09:09) Ness Ness's gravatar image

One Answer:

Ness,

thank you for the clarifying comment. It seems that the child assembly is not post-processed by PostSharp. This can be easily checked with the help of Reflector or DotPeek. Auto properties must be replaced by code like this:

[Field]
public string Version
{
    [CompilerGenerated, DebuggerNonUserCode]
    get { return base.GetFieldValue<string>("Version"); }
    [CompilerGenerated, DebuggerNonUserCode]
    set { base.SetFieldValue<string>("Version", value); }
}

Could you check this out? If the hypothesis is right, then you could run Project Upgrade Tool to fix the csproj file of child assembly (it will make all necessary corrections).

In future, use DataObjects.Net templates for new projects.

answered Jun 06 '11 at 09:39

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

edited Jun 06 '11 at 09:40

I've updated first post and added generated code.

(Jun 06 '11 at 10:16) Ness Ness's gravatar image

Ness,

do you have a copy of PostSharp installed?

(Jun 06 '11 at 10:31) Dmitri Maximov Dmitri%20Maximov's gravatar image

Yes, we have.

(Jun 06 '11 at 10:49) Ness Ness's gravatar image

Recently, one of our customers has faced with the similar problem. Eventually, the solution was found. This is what he told us:

it seems that I’ve found the problem. I had installed the latest PostSharp release (2.0.9.3) before I installed DataObjects.NET.
Removing my PostSharp version and installing the version from DataObjects.NET (2.0.8.1323) solved my problems.
(Jun 06 '11 at 10:58) Dmitri Maximov Dmitri%20Maximov's gravatar image

Yes, it solved our problem too :)

Thanks.

(Jun 06 '11 at 12:20) Ness Ness's gravatar image

You are welcome =)

(Jun 06 '11 at 12:55) Dmitri Maximov Dmitri%20Maximov's gravatar image

Latest DO does not work with PostSharp version 2.0.9.3 ?

(Jun 06 '11 at 14:50) Peter Šulek Peter%20%C5%A0ulek's gravatar image

Actually, it should. But in situations when another version of PostSharp is installed on a machine, some tricky problems occur. So, this definitely requires additional investigation.

(Jun 07 '11 at 04:08) 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