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

  • SEARCH
  • Home
  • 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 9174993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:50:34+00:00 2026-06-17T16:50:34+00:00

So I am trying to build Custom membership using EF. I dont really know

  • 0

So I am trying to build Custom membership using EF. I dont really know what i am doing but it has gone fairly smooth so far.

I am on the Database Initializer step where i am trying to dump data into the database soon as the project runs. My class Application.cs uses a GUID as a primary key as seen below. I am trying to figure out how i can add that GUID into the database.

I don’t know if this is possible but this is what i am trying to do. I took the default login’s Database you get when you make a normal web application project in VS 2012 and trying to recreate that database using EF Code First(For practice). This is what i got so far.

Class

public class Applications
        {

                [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
                public Guid ApplicationId { get; set; }

                [StringLength(125)]
                public string ApplicationName { get; set; }

        }

Intializer to dump data into db on build(not including Seed.)

 private static List<Applications> addApplications()
    {
        var apps = new List<Applications>
        {
            new Applications
            {
                ApplicationId = Guid.NewGuid(),
                ApplicationName = "Test Login"

            }
        };

        return apps;
    }
  private static List<Memberships> addMemberships()
    {
        var mem = new List<Memberships>
        {
            new Memberships
            {
                UserId = Guid.NewGuid(),
                ApplicationId = ?, // How can this guid Match the one in  
                                   // in ApplicationId for the Application Table?
            }

        };
        return mem;
    }

I get “Invalid Initializer member declarator”. The problem i face is that I need the GUIDS to be the same for ApplicationId across multiple tables. I don’t even know if this is possible or right?

I got a feeling I have to share it somehow maybe like

   Guid AppId;
        AppId = Guid.NewGuid();
  • 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-06-17T16:50:36+00:00Added an answer on June 17, 2026 at 4:50 pm

    In your Membership model instead of storing the GUID “ApplicationId” to try and reference the application you should use a navigation property like so (see this link for better description of navigation properties):

    public class Memberships
    {
    
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid UserId { get; set; }
    
        //if you set your model up like this entity framework will take care of creating
        /the foreign key for you.
        public Application MemberApplication { get; set; }
    
    }
    

    then just pass in the appropriate application to your method like so:

    private static List<Memberships> addMemberships(Application app)
    {
        var mem = new List<Memberships>
        {
            new Memberships
            {
                UserId = Guid.NewGuid(),
                Application = app, 
            }
    
        };
        return mem;
    }
    

    Setting your model up like this lets you take full advantage of oop and relational database. Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a custom segue, but i can't seem to get the
I'm fairly new to Android, and am trying to build a custom component in
I'm trying to build a menu using a UItableView with Custom cells which have
I am trying to build a custom TableViewCell, and so far I have created
I'm trying to build a custom function for ajax but the output is null
i am trying to build an custom validator with symfony2 but something strange happens:
I'm trying to build a custom framework but for some reason, there is never
I am trying to build some custom extensions onto EF (4.3) using ObjectQuery's ToTraceString()
This is really getting me frustrated. I'm trying to build a custom JavaScript app
I'm trying to build Custom Membership Provider. I would like to capture additional information

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.