Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to SQL DataContext.Translate and properties with name different than the source
    primarykey
    data
    text
    <p>I am working with some tables where I want the C# class to have a different property name than the underlying table column. However, when I use the Translate method to read the results, the properties that don't match the source name never get populated. Even when I use Linq to generate the SQL.</p> <p>For instance, my table is defined in the DB like this:</p> <pre><code>CREATE TABLE User_Entry ( UserId int IDENTITY (1, 1) NOT NULL, Login_Id varchar (50) NOT NULL, Active char(1) NOT NULL, PASSWORD varchar(75) NULL ) </code></pre> <p>Here's the class it maps to (generated by the LINQ designer...LINQ attributes and other stuff left out for brevity):</p> <pre><code>public partial class User { int UserId; string Login; string Active, string Pwd } </code></pre> <p>When I do the following, the Login and Pwd properties are not populated but the UserId and the Active properties are.</p> <pre><code>Data.DbContext db = new Data.DbContext(); IQueryable query = db.Users.Where(usr =&gt; usr.Login == request.LoginString); SqlCommand cmd = (SqlCommand)data.GetCommand(query); ... execute the command (asynchronously) ... User user = db.Translate&lt;User&gt;( dataReaderResult ).FirstOrDefault(); </code></pre> <p>!At this point, I inspect the user object and I can see that the Login and Pwd columns are not populated!</p> <p>Here is the sql that was generated:</p> <pre><code>exec sp_executesql N'SELECT [t0].[UserID] AS [UserId], [t0].[Login_ID] AS [Login], [t0].[Active], [t0].[PASSWORD] AS [Pwd] FROM [dbo].[User_Entry] AS [t0] WHERE [t0].[Login_ID] = @p0', N'@p0 varchar(13)', @p0 = 'test_user' </code></pre> <p>Originally, when the UserId column had a different property name I was getting an exception <code>The required column [UserId] does not exist in the results</code>. I looked around and I saw a response from some MSFT people that said it was a bug.</p> <p>Is this related? Was it ever fixed? Does anyone know when it will be fixed?</p> <p>Edit: Some more info.</p> <p>The bug that I think this is related to has a comment from Kathy Lu MSFT on 14 Aug 2007 <a href="https://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1983746&amp;SiteID=1&amp;pageid=0" rel="nofollow noreferrer">here</a>, where she says:</p> <blockquote> <p>Thank you for reporting this issue. From your issue we were able reproduce the issue and the product team is looking into an appropriate triage and resolution.</p> </blockquote> <p>I'm wondering if this is related to what I'm experiencing and if I can get more info about it. I searched <code>linq translate site:connect.microsoft.com</code> but I didn't find anything.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload