For example I have entities and do next

var item = Session.Current.Query.All<Ent1>().First();
var linkId0 = item.Entity.Id; // This initiate query
var linkId1 = (Guid)item.Entity.Key.Value.GetValue(0); // This too

Question is: Can I get Id from link without query to SQL?

public class Ent1 : Entity
{
    [Key]
    public Guid Id { get; }

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

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

public class Ent2 : Entity
{
    [Key]
    public Guid Id { get; }

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

asked Jun 04 '15 at 10:17

Anton%20Guschin's gravatar image

Anton Guschin
73293035


One Answer:

Hello Anton.

We have different services for direct access to Entities, Entity states and some other system objects. You need DirectEntityAccessor. You can get it from session


var entityAccessor = session.Serivces.Get<directentityaccessor>();// getting accessor
var keyOfEntity = entityAccessor.GetReferenceKey(item. item.TypeInfo.Fields["Entity"]);//getting Key of reference.

Then you can get value from key.

See also: all services.

answered Jun 08 '15 at 04:48

Alexey%20Kulakov's gravatar image

Alexey Kulakov
52715

edited Jun 08 '15 at 04:50

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

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×569
×11
×10

Asked: Jun 04 '15 at 10:17

Seen: 3,455 times

Last updated: Jun 08 '15 at 04:50

powered by OSQA