views:

34

answers:

4

I have an existing database that I'm access with LINQ to Entity in .NET 3.5 and I've run into an issue. One of the tables has a column named "from". This ends up screwing up LINQ when I try to join on it because from is a special word. Is there any way around this? I'm trying to avoid renaming that column since a lot of other things are using it.

+1  A: 

You can rename the column in the designer -- the names you use for properties in your model don't have to be the same as the names of the columns in your database.

Bennor McCarthy
+1  A: 

You can escape any keyword in C# with @, so use @from

Hopefully this helps

jayrdub
I can't believe I forgot about that!
GregInWI2
A: 

It can have one name in the database and another name in the conceptual model and generated code. If EF don't automagically change the name in the CSDL to From1 then try renaming it in the designer...

KristoferA - Huagati.com
A: 

You can always rename the public property variable to something else by using the edmx file. Goto edmx GUI and click on rename. There you should be able to change the property name from from to fromxyz. The result in designer.cs file looks like below.

   public global::System.Int32 fromxyz

            {
                get
                {
                    return _fromxyz;
                }
                set
                {
                    OnProjectIDChanging(value);
                    ReportPropertyChanging("");
                    _fromxyz = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("fromxyz");
                    OnProjectIDChanged();
                }
            }
A_Var