Linq to Sql saying that item by 'Customer' already exists. Choose a different name
I have been going round and round with a linq to sql file while using svn for quite some time. The latest is that my dbml file shows as having an error which states that
An item named "Customer" already exists. Please choose a different name.
And then it repeats t开发者_StackOverflow中文版hat again. In fact, it says it for almost every object. What is my fix? I have tried renaming the one named Customer, but that didn't fix it. I don't know where to go to fix this. I went to the .dbml file and don't see any duplication, and I went to the .dbml.layout file and didn't see any duplication there either.
Visual Studio reported the wrong item as a duplicate for me. So even when I removed the one it said was a duplicate ('Customers' above), it just kept reporting another one wrong until I gave up before actually getting to the one that really was a dupe.
Also, the duplicate is most likely at the end of the .dbml file (right click and choose 'Open With...' > 'XML (Text) Editor'). This happens because Visual Studio always moves any modifications to the end of the file so when two developers auto-merge after modifying the same item it's pretty easy to wind up with a dupe.
Run SqlMetal manually to get the actual error message:
- Start > Microsoft Visual Studio > Visual Studio Tools > Visual Studio Command Prompt
- Change directory (cd) to the directory with .dbml file
- (drag & drop a folder from Explorer to the command prompt window to get the path)
SqlMetal /code:[filename].designer.cs [filename].dbml
I don't believe you can have a member name with the same name as the class it belongs to, as in:
public class Customer
{
public string Customer { get; set; }
...
}
Check your entity.
Figured it out. Somehow there were duplicate associations. The part that confused me was that it looked like it was pointing to an object and didn't look like it was pointing to the association.
精彩评论