Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:57:33+00:00 2026-05-30T09:57:33+00:00

I have created a custom C# (4.0) class to be used in properties of

  • 0

I have created a custom C# (4.0) class to be used in properties of EF (4.1) model classes. The only property of this custom class has Guid as its type. Now, I would be interested to know if I could serialize my custom class into a Guid column on model tables as if it were a primitive type (supported by SQL Server 2008 R2).

Specifically, I do not wish to use plain Guid as property, as the model properties have conceptually distant meaning and functionality from Guid. I won’t be using the Guid as primary key. Rather, I will use it as a foreign key to access another table/collection that has non-primary Guid column/property (and several rows/instances with identical Guid). This may sound far-fetched but it would be very handy design for this specific purpose.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:57:34+00:00Added an answer on May 30, 2026 at 9:57 am

    Off the top of my head, I think the following approach might work with EF:

    1. Go ahead and add the GUID column to your model and database, but in your EF mapping, make its get and set accessors private or protected as appropriate.
    2. Add 2 implicit conversions to your custom class: one to convert from GUID to an instance of the class and one to convert from an instance of the class to GUID (see below for more on this).
    3. Create a partial class for the model class that exposes a public property of the custom type, and in the getter and setter just pass through to the private/protected GUID property (which you’ll be able to do by virtue of having implemented the implicit conversions).

    As far as EF is aware, you just have that Guid property, but as far as your model knows when you’re coding, you just have the custom type property.

    To create the implicit conversions:

    public class MyClass
    {
        public Guid Key { get; set; }
    
        public static implicit operator Guid(MyClass c)
        {
            return c.Key;
        }
    
        public static implicit operator MyClass(Guid g)
        {
            return new MyClass { Key = g; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a subclass of UITableViewController that is used as the custom class
I have created my custom MembershipProvider. I have used an instance of the class
I have a custom button control created using ATL. This control is used by
In my app i have created one custom class for Label.Now i want to
I have created a custom collection class that I am trying to bind to
I have a module that is used by creating a custom class loader. The
I have created a web custom control and used within an aspx page. I
Currently, I've created a class with ~30 properties to be set. This is done
I have a custom struct called TimeOfDay which is used in a view model
I have a Custom POCO (Already existing und used in my project). public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.