DeleteOnNull (Association attribute) for Linq to SQL in user class?

Is it possible to add “DeleteOnNull = true” to the user class instead of directly modifying the DBML class (generated)?

For example, let's say this is part of my generated dbml class:

[Table(Name="OrderDetails")] public partial class OrderDetail : INotifyPropertyChanging, INotifyPropertyChanged { // deleted for brevity [Association(Name="Order_OrderDetail", Storage="_Order", ThisKey="OrderId", OtherKey="OrderId", IsForeignKey=true, DeleteOnNull=true)] public Order Order { get { /* deleted */ } set { /* deleted */ } } } 

So, is it possible to put "DeleteOnNull = true" in a separate class? This is true? How? I tried the following with no luck:

 [MetadataType(typeof(OrderDetailMetadata))] public partial class OrderDetail { internal sealed class OrderDetailMetadata { [Association(DeleteOnNull = true)] public object Order; } } 
+4
source share
3 answers

Better late than never:

If you use the constructor to create your configuration and LTS objects, you can right-click on the DBML file and select "Open With ...". Now select the XML editor and click OK.

Find your Order_OrderDetail association in this file, then add DeleteOnNull="true" to it. Save the file and let LTS re-generate your classes for you. Done! No more overwriting your generated code files!

+1
source

You may not need the type MetaData. Will this work in your extra partial:

 public partial class OrderDetail { [Association(DeleteOnNull = true)] public Order Order; } 

.. I know that Order itself is not defined, but you do not need to build it like that. This MSDN document suggests that this should be possible (if I read it correctly).

+1
source

I would build an assembly and then use a reflector to add a class to find out if it has attribute properties defined from a partial class. If this does not even work, you may need to try something else. This type of attribute overlap may not be supported.

What are you trying to achieve through this?

0
source

All Articles