score:2
Agreed. I found no possible way of doing this nor using the designer nor by hand appending class/method attributes. Moreover is not possible to have foreign key constraints for polymorphic associations. I discarded this option, thanks.
score:1
EDITTED
SQL Server won't allow you to have a foreign key relationship on a column that is not a primary key or doesn't have a unique constraint (or index) on it. There doesn't seem to be any restriction on having multiple tables use the same column in the child table as the foreign key. The DBML designer does discover these relationships and will create associations to both parent tables when you import the table. It appears however, that the designer-generated code will only be generated for one of the associations. That is, the designer shows the associations properly, but the code for all but one of them is omitted. Further, the extensibility methods and property settors don't seem to get defined properly in the designer-generated code either.
The same seems to be true if you add the associations by hand in the designer. Only one of the actual associations is implemented in the code and the other parent class's code seems irretrievably broken. It's possible that you may be able to use partial class implementations to add in the required functionality to match what the designer would generate, but I haven't tried this.
Also, LINQ2SQL doesn't support many-to-many relationships out of the box. You're limited to 1-1 and 1-many without writing the code yourself.
Source: stackoverflow.com
Related Articles
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- Polymorphic associations in LINQ to SQL
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Syntax to execute code block inside Linq query?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Best open source LINQ provider
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ WHERE method alters source collection
- Where can I view LINQ source code?
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- How to access associations in a LINQ query?
- Left outer join using LINQ -- understanding the code
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- Polymorphic Associations in .NET
- How does linq actually execute the code to retrieve data from the data source?
- How can I switch that code to use LINQ
- How does this linq code that splits a sequence work?
- LINQ greater/less than not working in query
- LINQ Query for GroupBy and Max in a Single Query
- How to select rows from a DataTable where a Column value is within a List?
- Retrieve data from xml (malformed?) c#
- How to compare two list values and round them to first list values without adding them internally
- Use string variable in LINQ lambda expression
- How to convert anonymous type to IListSource, IEnumerable, or IDataSource
- Can I trap an exception in a LINQ projection?
- Is LINQ faster or just more convenient?
- Linq query to check for two values
- How to execute linq queries in ranking?
- How to make LINQ to EF query more efficient
- Converting a list of objects to a list of an object property
- Linq to Entities and reversing a column
- Load N records from database in entity framework
- What is a possible interface to return for Entity framework entity classes?
- Combine two lists into one based on property
- Use variable from selected row on mysql
- Use of Expression in LINQ query
- ObjectQuery<T> or IQueryable<T>