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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:43:05+00:00 2026-06-15T04:43:05+00:00

I am trying to insert an object into my database using Entity Framework where

  • 0

I am trying to insert an object into my database using Entity Framework where two of the properties represent the result of the SQL Server soundex function, and I can’t find anything pointing me in the right direction.

A vastly simplified example of my code:

C# Object

public class Person{
    string FirstName
    string LastName
    string FirstNameSE
    string LastNameSE
}

Table Structure:

FirstName   varchar(50)
LastName    varchar(50)
FirstNameSE varchar(4)
LastNameSE  varchar(4)

Insert Method

public static void InsertIntoDatabase(Person vPerson){
    using (var db = new DatabaseContext()) {
        db.People.Add(vPerson);
        db.SaveChanges();
    }
}

This works, but I need FirstNameSE and LastNameSE to be set to soundex(FirstName) and soundex(LastName) respectively, I can’t figure out how to do that on the insert.

I’ve found out how I can use the SqlFunctions class in LINQ to Entities select statements, but that doesn’t help me when I’m trying to insert data.

  • 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-15T04:43:06+00:00Added an answer on June 15, 2026 at 4:43 am

    I think you might be stuck making a couple round trips.
    Something like this might suffice (error handling elided for brevity):

    public static void InsertIntoDatabase(Person vPerson){
        using (var db = new DatabaseContext()) {
            var soundExQuery = db.People.Select(p => 
                  new { 
                          FirstNameSE = SqlFunctions.SoundCode(vPersion.FirstName), 
                          LastNameSE = SqlFunctions.SoundCode(vPersion.LastName) 
                }
            ).Take(1);
    
            var result = soundExQuery.ToArray();
    
            vPerson.FirstNameSE = result[0].FirstNameSE;
            vPersion.LastNameSE = result[0].LastNameSE;
            db.People.Add(vPerson);
            db.SaveChanges();
        }
    }
    

    Make one round trip to get the sound codes, then insert them.

    Yes, its not very clean, but I think your only other option is to drop to straight SQL.

    db.ExecuteStoreCommand(
        @"INSERT INTO People (FirstName, LastName, FirstNameSE, LastNameSE) 
        VALUES ({0}, {1}, SOUNDEX({0}), SOUNDEX({1}))"
        , vPerson.FirstName, vPerson.LastName);
    

    Note that ExecuteStoreCommand does SQL Parameterization automatically. (its not a string.Format).

    http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.executestorecommand.aspx

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

Sidebar

Related Questions

How can I insert data into my database using Entity Framework ? I'm trying
I was trying to insert values into an Access database using a parameterized query:
Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and
I'm trying to authenticate before using ajax to insert into a database $('#button').click(function ()
I'm trying to insert a number into the database from within a library using,
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
In my application I am trying to insert the embedded (video) into database, but
I am new to working with the Entity Framework with SQL Server and I
I'm trying to do an insert or update in a postgres database using node.js
I'm trying to do a huge bulk insert into an SqlCe database (version 3.5,

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.