New Posts New Posts RSS Feed: [SOLVED] Return a Null Entity as a property
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

[SOLVED] Return a Null Entity as a property

 Post Reply Post Reply
Author
HFloyd View Drop Down
Groupie
Groupie


Joined: 27-Jul-2007
Location: United States
Posts: 44
Post Options Post Options   Quote HFloyd Quote  Post ReplyReply Direct Link To This Post Topic: [SOLVED] Return a Null Entity as a property
    Posted: 24-Aug-2008 at 3:14pm
Hi,

I am trying to return one entity out of an object's relational collection, but was getting an error if the collection was empty, so I added a check for an empty collection. If the collection is empty, I would like to return the NullEntity, but am having problems with the syntax to accomplish this.

The object model is thus: I have a Person entity, with a relation to "Involvements" (which indicate what roles a person has played in the organization).

This is my property code (Located in the Person Class):

/// <summary>
    /// The latest Involvement (aka Staff, Board, Volunteer)
    /// </summary>
    public Involvement LatestInvolvement
    {
        //TODO: Finish Person.LatestInvolvement & Test (Need test data in DB)
        get
        {
            ReadOnlyEntityList<Involvement> myList;
            Involvement rInvolvement;

            myList = this.Involvements;
            myList.ApplySort("AuctionYear", System.ComponentModel.ListSortDirection.Descending, true); // Get the line items

            if (myList.Count > 0)
            { rInvolvement= myList[0]; }
            else
            { rInvolvement = NullEntity; }

            return rInvolvement;
        }
    }


My problem occurs at the bolded line: "{ rInvolvement = NullEntity; }"

The Build error I get is:

Cannot implicitly convert type 'IdeaBlade.Persistence.Entity' to 'HS.Admin.Model.Involvement'. An explicit conversion exists (are you missing a cast?)   

I'm not sure what cast would be appropriate.

Thanks for any insights into how I can accomplish this.

Heather





Edited by HFloyd - 05-Sep-2008 at 12:18pm
Back to Top
jeffdoolittle View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 146
Post Options Post Options   Quote jeffdoolittle Quote  Post ReplyReply Direct Link To This Post Posted: 24-Aug-2008 at 5:51pm
You should return this:

return PersistenceManager.GetNullEntity<Involvement>();





Back to Top
HFloyd View Drop Down
Groupie
Groupie


Joined: 27-Jul-2007
Location: United States
Posts: 44
Post Options Post Options   Quote HFloyd Quote  Post ReplyReply Direct Link To This Post Posted: 25-Aug-2008 at 11:29am
Thanks, Jeff!

You're awesome!

Heather

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down