Forums
Forums are Read-Only. Use the new Support Center. To start a general discussion, use the General category when submitting your question.

Linq to XPO problem when use join with GUID values, Help me!

Last post 6/25/2010 6:23 AM by Oliver Sturm. 4 replies.
Sort Posts: Previous Next
  • Emilio Garcia

    Linq to XPO problem when use join with GUID values, Help me!

    6/10/2010 2:15 PM
    • Not Ranked
    • Joined on 5/22/2010
    • Posts 5

     Hi, I've a question... before anything excuse my english!!

    I trying to create a linq query to retrive some objects, this is the query:

     

     

     

     

     

     

     

    The u.ObjId and s.UsuarioId are of Guid type and this query raise a NotSupportedException, what happend??? help my please!!!

    I thing that Linq to XPO join opperant not support Guid arguments

     

    var

     

     

    listadoSesiones = from u in usuariosjoin s in sesiones on u.ObjId equals s.UsuarioIdwhere s.Activa == true

     

    orderby s.FechaInicio ascending

     

    select new { u.NombreUsuario, u.NombreCompleto, s.FechaInicio, s.FechaFin };

     

  • Tolis Bekiaris [DX-Squad]

    Re: Linq to XPO problem when use join with GUID values, Help me!

    6/10/2010 2:23 PM
    • Top 50 Contributor
    • Joined on 6/21/2007
    • Posts 592

     

    Hi

    this may help u

     

    http://documentation.devexpress.com/#XPO/CustomDocument4060

  • Emilio Garcia

    Re: Linq to XPO problem when use join with GUID values, Help me!

    6/10/2010 3:57 PM
    • Not Ranked
    • Joined on 5/22/2010
    • Posts 5

     Hi, sorry for my post, I don't know beacose dosen't show correctly... anyway... The code that I show in the post above compile ok! bot in runtime raise a NotSupportedException and VS stopped in this code... I thing that Linq to XPO Join opperant not support GUID property types as a part of equals, please can you confirm me this??

  • Oliver Sturm

    Re: Linq to XPO problem when use join with GUID values, Help me!

    6/25/2010 6:12 AM
    • Top 500 Contributor
    • Joined on 3/25/2010
    • Scotland
    • Posts 52
    Emilio Garcia wrote:

    > I trying to create a linq query to retrive some objects, this is the query:

    > var
    > listadoSesiones = from u in usuariosjoin s in sesiones on u.ObjId equals
    > s.UsuarioIdwhere s.Activa == true
    > orderby s.FechaInicio ascending
    > select new { u.NombreUsuario, u.NombreCompleto, s.FechaInicio, s.FechaFin };

    I'm pretty sure this doesn't have anything to do with the Guid type.
    Instead, the problem is the projection you're trying to do. Instead, you
    should define your classes correctly and things should be much easier...

    I'm roughly translating your names, and I'm coming up with classes that
    look like this:

    public class User: XPObject {
    public User(Session session)
    : base(session) { }

    private string userName;
    public string UserName {
    get {
    return userName;
    }
    set {
    SetPropertyValue("UserName", ref userName, value);
    }
    }

    private string fullName;
    public string FullName {
    get {
    return fullName;
    }
    set {
    SetPropertyValue("FullName", ref fullName, value);
    }
    }

    [Association("User-Sessions")]
    public XPCollection Sessions {
    get {
    return GetCollection("Sessions");
    }
    }
    }

    public class LoginSession: XPObject {
    public LoginSession(Session session)
    : base(session) { }

    private DateTime startTime;
    public DateTime StartTime {
    get {
    return startTime;
    }
    set {
    SetPropertyValue("StartTime", ref startTime, value);
    }
    }

    private DateTime endTime;
    public DateTime EndTime {
    get {
    return endTime;
    }
    set {
    SetPropertyValue("EndTime", ref endTime, value);
    }
    }

    private bool active;
    public bool Active {
    get {
    return active;
    }
    set {
    SetPropertyValue("Active", ref active, value);
    }
    }

    private User user;
    [Association("User-Sessions")]
    public User User {
    get {
    return user;
    }
    set {
    SetPropertyValue("User", ref user, value);
    }
    }
    }

    Note the two properties marked with [Association] - these are the ones
    that implement the relationship for XPO. You should always set these
    relationships up correctly, then it will be much easier to get to the
    right data...

    (As an aside - when working with legacy databases, you'll sometimes need
    to use the [Persistent(...)] attribute on properties like this to define
    the name of the foreign key fields in your database.)


    Once you've got your classes set up like this, you can easily query the
    information you were looking for, utilizing these pre-configured
    relationships:

    using (UnitOfWork unitOfWork = new UnitOfWork( )) {
    var activeSessions =
    from s in new XPQuery(unitOfWork)
    where s.Active
    orderby s.StartTime
    select new {
    s.User.UserName,
    s.User.FullName,
    s.StartTime,
    s.EndTime // why this? session is active, no end time...
    };
    foreach (var session in activeSessions)
    Console.WriteLine("Username: {0}, Full name: {1}, Start time: {2}",
    session.UserName, session.FullName, session.StartTime);
    }


    Of course on the other hand there's no real need to do this either -
    it's so easy to get to the data you need through the relationship
    properties, you don't need to work with projection.

    Hope this helps
    Cheers
    Oliver

    Consulting and Training Services, DevExpress Expert
    http://www.oliversturm.com - http://www.dxtraining.com
  • Oliver Sturm

    Re: Linq to XPO problem when use join with GUID values, Help me!

    6/25/2010 6:23 AM
    • Top 500 Contributor
    • Joined on 3/25/2010
    • Scotland
    • Posts 52

    Sorry, my reply was somewhat mangled. I put up the info here: http://www.sturmnet.org/blog/2010/06/25/relationships-in-xpo Have fun!

    Cheers
    Oliver

    Consulting and Training Services, DevExpress Expert
    http://www.oliversturm.com - http://www.dxtraining.com
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.