This is a migrated thread and some comments may be shown as answers.

BitmapSource Artificial Field

8 Answers 70 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Garry
Top achievements
Rank 1
Garry asked on 11 May 2010, 04:30 PM
Quick question I have a forward mapped class that is basically a person class. I am wanting to add a BitmapSource field to the class so that I can have an easy way to display a gender specific icon. Currently this is working off of a placeholder class I developed just so I could see the UI work until I could incorporate the OpenAccess live data. I am now at that point. Would an Artificial Field be the best way to handle this or am I looking at this from the wrong point of view? I basically want to add this

public BitmapSource GenderIcon  
        {  
            get 
            {  
                if (Gender.StartsWith("F", StringComparison.OrdinalIgnoreCase))  
                {  
                    return ResourceService.CreateBitmapSource(new System.Drawing.Bitmap(Resources.Female));  
                }  
                else 
                {  
                    return ResourceService.CreateBitmapSource(new System.Drawing.Bitmap(Resources.Male));  
                }  
            }  
        } 

to this

using System;  
using System.Collections.Generic;  
 
namespace EliteExtender.Infrastructure.Models.Elite  
{  
    // Generated by Telerik OpenAccess  
    // Used template: c:\program files (x86)\telerik\openaccess orm\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class\partialuserdefault.vm  
    // NOTE: Field declarations and 'Object ID' class implementation are added to the 'designer' file.  
    //       Changes made to the 'designer' file will be overwritten by the wizard.       
    public partial class PtWMember  
    {  
        //The 'no-args' constructor required by OpenAccess.   
        public PtWMember()  
        {  
        }  
 
        [Telerik.OpenAccess.FieldAlias("pk")]  
        public int Pk  
        {  
            get { return pk; }  
            set { this.pk = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("alienRegistrationNumber")]  
        public string AlienRegistrationNumber  
        {  
            get { return alienRegistrationNumber; }  
            set { this.alienRegistrationNumber = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("cityOfBirth")]  
        public string CityOfBirth  
        {  
            get { return cityOfBirth; }  
            set { this.cityOfBirth = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("countryOfBirth")]  
        public string CountryOfBirth  
        {  
            get { return countryOfBirth; }  
            set { this.countryOfBirth = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("dateOfBirth")]  
        public DateTime? DateOfBirth  
        {  
            get { return dateOfBirth; }  
            set { this.dateOfBirth = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("disguisedSSN")]  
        public string DisguisedSSN  
        {  
            get { return disguisedSSN; }  
            set { this.disguisedSSN = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("driversLicenseNumber")]  
        public string DriversLicenseNumber  
        {  
            get { return driversLicenseNumber; }  
            set { this.driversLicenseNumber = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("elevatedBloodLeadLevel")]  
        public string ElevatedBloodLeadLevel  
        {  
            get { return elevatedBloodLeadLevel; }  
            set { this.elevatedBloodLeadLevel = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("emailAddress")]  
        public string EmailAddress  
        {  
            get { return emailAddress; }  
            set { this.emailAddress = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("evictingAgency")]  
        public string EvictingAgency  
        {  
            get { return evictingAgency; }  
            set { this.evictingAgency = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("evictionCity")]  
        public string EvictionCity  
        {  
            get { return evictionCity; }  
            set { this.evictionCity = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("evictionDate")]  
        public DateTime? EvictionDate  
        {  
            get { return evictionDate; }  
            set { this.evictionDate = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("evictionState")]  
        public string EvictionState  
        {  
            get { return evictionState; }  
            set { this.evictionState = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("familyMemberID")]  
        public string FamilyMemberID  
        {  
            get { return familyMemberID; }  
            set { this.familyMemberID = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("firstName")]  
        public string FirstName  
        {  
            get { return firstName; }  
            set { this.firstName = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("fkMLSosCodeCitizenship")]  
        public int? FkMLSosCodeCitizenship  
        {  
            get { return fkMLSosCodeCitizenship; }  
            set { this.fkMLSosCodeCitizenship = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("fkMLSosCodeCommunityService")]  
        public int? FkMLSosCodeCommunityService  
        {  
            get { return fkMLSosCodeCommunityService; }  
            set { this.fkMLSosCodeCommunityService = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("fkMLSosCodeEthnicity")]  
        public int? FkMLSosCodeEthnicity  
        {  
            get { return fkMLSosCodeEthnicity; }  
            set { this.fkMLSosCodeEthnicity = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("fkMLSosCodeRelationship")]  
        public int? FkMLSosCodeRelationship  
        {  
            get { return fkMLSosCodeRelationship; }  
            set { this.fkMLSosCodeRelationship = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("fkptCustomRelationship")]  
        public int? FkptCustomRelationship  
        {  
            get { return fkptCustomRelationship; }  
            set { this.fkptCustomRelationship = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("fkptWCertification")]  
        public int FkptWCertification  
        {  
            get { return fkptWCertification; }  
            set { this.fkptWCertification = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("gender")]  
        public string Gender  
        {  
            get { return gender; }  
            set { this.gender = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("isOwnBedroomRequired")]  
        public string IsOwnBedroomRequired  
        {  
            get { return isOwnBedroomRequired; }  
            set { this.isOwnBedroomRequired = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("isVeteran")]  
        public string IsVeteran  
        {  
            get { return isVeteran; }  
            set { this.isVeteran = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("lastName")]  
        public string LastName  
        {  
            get { return lastName; }  
            set { this.lastName = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("lastTestElevatedBloodLeadLevel")]  
        public DateTime? LastTestElevatedBloodLeadLevel  
        {  
            get { return lastTestElevatedBloodLeadLevel; }  
            set { this.lastTestElevatedBloodLeadLevel = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("middleName")]  
        public string MiddleName  
        {  
            get { return middleName; }  
            set { this.middleName = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("namePrefix")]  
        public string NamePrefix  
        {  
            get { return namePrefix; }  
            set { this.namePrefix = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("nameSuffix")]  
        public string NameSuffix  
        {  
            get { return nameSuffix; }  
            set { this.nameSuffix = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("pregnancyDueDate")]  
        public DateTime? PregnancyDueDate  
        {  
            get { return pregnancyDueDate; }  
            set { this.pregnancyDueDate = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("qualifiedDisabilityAllowance")]  
        public string QualifiedDisabilityAllowance  
        {  
            get { return qualifiedDisabilityAllowance; }  
            set { this.qualifiedDisabilityAllowance = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("qualifiedElderlyAllowance")]  
        public string QualifiedElderlyAllowance  
        {  
            get { return qualifiedElderlyAllowance; }  
            set { this.qualifiedElderlyAllowance = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("qualifiedMinorAllowance")]  
        public string QualifiedMinorAllowance  
        {  
            get { return qualifiedMinorAllowance; }  
            set { this.qualifiedMinorAllowance = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("qualifiedStudentAllowance")]  
        public string QualifiedStudentAllowance  
        {  
            get { return qualifiedStudentAllowance; }  
            set { this.qualifiedStudentAllowance = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("socialSecurityNumber")]  
        public string SocialSecurityNumber  
        {  
            get { return socialSecurityNumber; }  
            set { this.socialSecurityNumber = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("stateOfBirth")]  
        public string StateOfBirth  
        {  
            get { return stateOfBirth; }  
            set { this.stateOfBirth = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("mLSosCodeCitzenship")]  
        public MLSosCode MLSosCodeCitzenship  
        {  
            get { return mLSosCodeCitzenship; }  
            set { this.mLSosCodeCitzenship = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("mLSosCodeCommunityService")]  
        public MLSosCode MLSosCodeCommunityService  
        {  
            get { return mLSosCodeCommunityService; }  
            set { this.mLSosCodeCommunityService = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("mLSosCodeEthnicity")]  
        public MLSosCode MLSosCodeEthnicity  
        {  
            get { return mLSosCodeEthnicity; }  
            set { this.mLSosCodeEthnicity = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("mLSosCodeRelationship")]  
        public MLSosCode MLSosCodeRelationship  
        {  
            get { return mLSosCodeRelationship; }  
            set { this.mLSosCodeRelationship = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("ptWorkingCertification")]  
        public PtWorkingCertification PtWorkingCertification  
        {  
            get { return ptWorkingCertification; }  
            set { this.ptWorkingCertification = value; }  
        }  
 
 
    }  
}  
 

Any help or suggestions would greatly be appreciated.

Thanks!

8 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 12 May 2010, 05:37 AM
Hi Garry,

I think you can use your code as it is as long as you don't have a field in your class to hold the bitmap. OpenAccess works on class fields (not properties) to persist data. So, do it as you already do, by implementing a public getter property, which uses a persistent field (here: Gender) to decide what BitmapSource to return.

Regards

Henrik
0
Garry
Top achievements
Rank 1
answered on 12 May 2010, 12:51 PM
Henrick,
Thank you for your response. My question though is if I put the property inside the persisted class the next time I change the schema for the table changes and OpenAccess remaps the table to the persisted class my property will be lost correct?

I maybe to worried about loosing the property as I am not sure how often that paticular table changes.  I just hate the possibility of breaking code on down the road if and when it does in fact get modified.
0
IT-Als
Top achievements
Rank 1
answered on 12 May 2010, 02:27 PM
Hi Garry,

You are doing forward mapping right? When you will never loose the property since it is not backed by a field in the class and thus not persisted. So nothing get lost there...  Bu if you do reverse mapping the story is a bit different.

Regards

Henrik
0
Garry
Top achievements
Rank 1
answered on 12 May 2010, 02:30 PM
My apologies. I did state forward mapping, but did in fact mean reverse mapping. The classes are generated from the DB tables. Again thank you for your response.
0
IT-Als
Top achievements
Rank 1
answered on 15 May 2010, 08:12 AM
Hi Garry,

Maybe you can check this article.

When you reverse map from a database you'll get two partial classes... one with the private fields (this gets generated each time you reverse map)...and one with the public properties backing the private fields... So you can put your custom code in the partial class file with the public properties.

Regards

Henrik
0
Ady
Telerik team
answered on 17 May 2010, 09:06 AM
Hello Garry Clark,

 As rightly suggested by Henrik, you can implement the 'GenderIcon' property in the <classname>.cs file of your class. The 'Reverse mapping wizard' generates 2 files for each class - <classname>.cs and <classname>.Telerik.OpenAccess.cs. When you update a table and regenerate the class, only the <classname>.Telerik.OpenAccess.cs file is regenerated.

Do get back to us in case you need further assistance.

All the best,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Garry
Top achievements
Rank 1
answered on 17 May 2010, 12:41 PM
Henrik and Ady,
Thank you both for your responses and I apologize for not updating my post. I had figured that out a few days ago and had updated my pulic property class. Works like a charm! The more I dig into OpenAccess the more I am liking it.

Thank you both for the excellent responses. Another reason why I always recommend Telerik to colleagues is mainly due to the support I get!

Thanks,
Garry
0
Ady
Telerik team
answered on 19 May 2010, 11:39 AM
Hi,

 @Henrik: Thank you for your valuable answers.

@Garry:  We are glad that you like working with OpenAccess.

Please feel free to get back to us in case you need further assistance.We would be glad to help.

Kind regards,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Development (API, general questions)
Asked by
Garry
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Garry
Top achievements
Rank 1
Ady
Telerik team
Share this question
or