0

I have a dbml file and dropped a Products table onto it. I now have access to the auto generated Products class file which is great.

I would like to export a CSV file's content and save it to this table, so i decided to go with Linq to CSV http://aspnetperformance.com/post/LINQ-to-CSV-library.aspx

It seems in order for the file to be read, a property needs to be decorated with an attribute i.e.

<CsvColumn(Name:= "ProductName", FieldIndex:= 1)>

But when i use the Products class it returns an error that the column name cant be found (i know this, as i created a different project which read the file without issues once the above attribute was added)

So i created a partial class and added the attribute:

<Metadatatype(GetType(ProductsMetadata))> _
Partial Public Class Products

End Class

Friend Class ProductsMetadata

<CsvColumn(Name:= "ProductName", FieldIndex:= 1)>
Public Property ProductName As String

End Class

However this still didnt work. The reason why i need to add an attribute is so when i save it i can pass in the Products object into the save method

myDataContext.Products.InsertOnSubmit(ProductObject)
myDataContext.SubmitChanges()

Is it possible to add attributes in the above manner or any other way i could do this?

4

1 回答 1

0

不是不编辑生成的文件。分部类可用于向类型添加属性,并向类型添加成员 - 但您不能向分部类的另一部分中的成员添加属性。如果我们可以,那就太好了,我同意。

于 2013-10-10T17:10:41.110 回答