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 475589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:24:13+00:00 2026-05-13T00:24:13+00:00

I have created a universalrepository that takes the type passed to it and when

  • 0

I have created a universalrepository that takes the type passed to it and when I create data entry method, the entity is created fine, but when I create a linked entity to it, i get the base entity created again. Any ideas why?

Details..

I have divided a specification into multiple tables to manage stuff…

Now I have got a person entity, an applicant entity…(in reality applicant and person are the same), a contractor entity. A contractor can only be created by an applicant and therefore an applicant will always be created and therefore a person will always be created.

When I go on creating a person, it creates a person fine, but when I create an applicant it creates a person again. Likewise when I create a contractor it creates a person and multiple applicants for some reason.

Here is my LINQ to SQL. If you notice in anyway I can improve this code, I will appreciate that too.

here is the repository

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

namespace ParkingPermit.Models
{
    public class UniversalManagerRepository<T> :IRepositoryT<T>
                                               where T:class
    {
        private Table<T> _table;
        private readonly DB _db ;//= new DB();

        public UniversalManagerRepository()
        {
            _db = new DB();
            _table = _db.GetTable<T>();
        }

        #region IRepositoryT<T> Members

        public T Create(T create)
        {

           // _table = new DB().GetTable<T>();

            //_db.GetTable(typeof(T)).InsertOnSubmit(create);

            _table.InsertOnSubmit(create);
            Save();

            return create;
        }

        public void Delete(T delete)
        {
            throw new NotImplementedException();
        }

        public T Edit(T edit)
        {
            throw new NotImplementedException();
        }

        public T GetItem(int id)
        {
            throw new NotImplementedException();
        }

        public T Update(T update)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<T> List()
        {
            //IQueryable i = _db.GetTable(typeof(T)).AsQueryable()  ;
            return _db.GetTable(typeof(T)) as IEnumerable<T>;
            //throw new NotImplementedException();
        }

        public void Save()
        {
            //_db.SubmitChanges();
            _table.Context.SubmitChanges();
            //throw new NotImplementedException();
        }

        #endregion
    }
}

I can post an image of the linq to sql designer if that helps, but I cant see the feature here…

Many thanksalt text http://img509.imageshack.us/img509/2072/linq.jpg

the thing is that when applicant is added and an applicant.Person is assigned from the session(in model binder), it creates a new person, which is actually the original person created in the beginning. How can I avoid that.

protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)  
{  
   var personType = (Person)controllerContext.HttpContext.Session[PersonSessionKey];  

   controllerContext.HttpContext.Session[CurrentApplicantSessionKey] = null;  

   var av = new ApplicantValidator(new            ModelStateWrapper(bindingContext.ModelState));  
   var newApplicant = bindingContext.Model as Applicant;  




   if (personType == null)  
   {  

       bindingContext.ModelState.AddModelError(bindingContext.ModelName,  

                                               "Cannot Update this Instance directly, please restart the application");  
      // controllerContext.HttpContext.Session[PersonSessionKey] = personType;  
   }  
   else if (newApplicant != null)  
   {  
       if (newApplicant.Person != null)  
       {  
           if (newApplicant.Person.Equals(personType as Person))  
           {  
               bindingContext.ModelState.AddModelError(bindingContext.ModelName,  
                                                       "A person with these details already exists, please restart the application...");  
               //return  
               controllerContext.HttpContext.Session[PersonSessionKey] = null;  
               personType = null;  
           }  
       }  
       else if (av.Validate(newApplicant))  
       {  

           if (newApplicant.Person == null)  
           {  

               newApplicant.Person = personType as Person;  
               newApplicant.PersonId = personType.PersonId;  


           }  
       }  

   }  

}  
  • 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-13T00:24:14+00:00Added an answer on May 13, 2026 at 12:24 am

    I have resolved this part and apparently its now giving issued with update, can anbody find anything unusual.

    1. Answer to my first problem, was that in Model Binders the entity is being manipulated from sessions and the created back to the service layer.

    Apparently it seems that because its all happening outside linq orm framework, this entity needs to be recreated as “From clause …from ..in db.” and then linq correctly recognizes it and does the correct job of insertion.

    Can anyone help me with the update/edit..please

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

Sidebar

Related Questions

I have created form using ModelForm but its not saving data into database. views.py
I have created enemies that chase the player around a game, but there is
i have created a table in mysql to store polygon data: CREATE TABLE geom
I have created a mac application using the WebView. But issue is that webView
I have created a facebook apps. It works fine for me. But my problem
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
Have created simple Ajax enabled contact forms before that have around 12 fields -

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.