1

in my db I have two tables that are related. Lets call them Job and JobType Job has a foreign key jobTypeID that references JobType.

I would like to create a custom class in the dbml with properties from both of the DB tables...essentially all of the Job properties and the JobTypeName property from JobType

This is a simplified example but id like to know if this is even possible before I continue.

Ultimately I need a linqtosql class with the appropriate properties to pass to a parser which handles paging, sorting, etc for a client side data grid...

If it helps to point me in a better direction, the parser takes an IQueryable with a generic type...the type being the linqtosql class that holds the data that will be displayed in the table.

2 Answers 2

1

since all your tables got relations and successfully transferred to the DBML then yes you can do that

basically create a partial class for you Job class (partial class to refer to the Job class created by Linq Designer) and put a property inside it that returns the JobTypeName from referenced table

e.g.:

namespace ConsoleApplication1
{
    /// <summary>
    /// Partial class for job class created by LINQ Desinger
    /// </summary>
    public partial class Job
    {
        /// <summary>
        /// Property to return the JobTypeName for this Job
        /// </summary>
        public string JobTypeName
        {
            get
            {
                if (JobType != null)
                    return this.JobType.JobTypeName;
                return string.Empty;
            }
        }
    }
}

Hope this helped.

Sign up to request clarification or add additional context in comments.

Comments

0

Well I did get this to work but not the way I had intitially imagined...

I was able to create a view in the db to return the columns needed then map the view to a linqtosql class.

Performance seems to be OK for the time being.

I am guessing the proper approach would be to explore ado.net entity framework for future projects

1 Comment

accepted different answer but this solution did work for me in a pinch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.