using

[Field(DefaultValue = "2001-03-04")]
public DateTime Date { get; set; }

is OK but how to use it with link? for example:

[Serializable]
[HierarchyRoot]
public class MyEntity : Entity
{
    [Field, Key]
    public int Id { get; private set; }

    [Field(Length = 100)]
    public string Text { get; set; }
}

[Serializable]
[HierarchyRoot]
public class MyEntity2 : Entity
{
    [Field, Key]
    public int Id { get; private set; }

    [Field(Nullable = false, DefaultValue = 1)]
    public MyEntity MyEntity { get; set; }
}

I got error on domain build: Invalid cast from 'System.Int32' to 'Project3.Model.MyEntity'. or Invalid cast from 'System.String' to 'Project3.Model.MyEntity'. for DefaultValue = "1"

I think string default values for referential fields should be converted to Keys, so, if there exists entity with Key 1 - use it. translating to sql should be simple for GUID - if use DefaultValue = "68DBEE55-09A7-48B3-9A47-4E16549B24B6" find linked entity with this key and use it.

asked Sep 02 '10 at 06:05

pil0t's gravatar image

pil0t
207575763

edited Sep 02 '10 at 10:37

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412


One Answer:

Although it's a bad idea to use DefaultValue for reference types, the bug will be fixed.

Actually, we had no time to implement support of this attribute for reference fields at all - I'm still thinking if this is a good idea, or not.

Issue: 793.

answered Sep 02 '10 at 10:34

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

edited Sep 02 '10 at 10:35

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