Click here to Skip to main content
16,017,650 members
Home / Discussions / C#
   

C#

 
GeneralRe: working around 'using wrapped MemoryStream immutability ? Pin
Richard Deeming10-Aug-17 4:01
mveRichard Deeming10-Aug-17 4:01 
QuestionEntity Framework 4 mapping problems Pin
Member 109427609-Aug-17 13:19
Member 109427609-Aug-17 13:19 
AnswerRe: Entity Framework 4 mapping problems Pin
Gerry Schmitz11-Aug-17 5:55
mveGerry Schmitz11-Aug-17 5:55 
GeneralRe: Entity Framework 4 mapping problems Pin
Member 1094276011-Aug-17 9:11
Member 1094276011-Aug-17 9:11 
Questionquery to retrieve Gujarati Pin
Member 129573749-Aug-17 0:44
Member 129573749-Aug-17 0:44 
AnswerRe: query to retrieve Gujarati Pin
Afzaal Ahmad Zeeshan9-Aug-17 0:53
professionalAfzaal Ahmad Zeeshan9-Aug-17 0:53 
AnswerRe: query to retrieve Gujarati Pin
BillWoodruff9-Aug-17 15:44
professionalBillWoodruff9-Aug-17 15:44 
QuestionC# writing to a csv file, adds an extra column Pin
Member 128805958-Aug-17 23:22
Member 128805958-Aug-17 23:22 
Hello,
I am trying to write a database table to a csv file.
It works, but the problem i have is that it adds an "extra column" without a header but the rest of the cells containing:
System.Data.Linq.EntitySet`1[BookLendingLib.Models.RentedBook]


I am using LinqToSql for my database, and i have 3 tables: Books, Readers, and RentedBooks(RentedBooks being an associative table with BookId and ReaderId to define the books rented by a reader).
In my database designer file the RentedBook is "tagged" as an AssociationAttribute and i assume its related to the RentedBooks table.
What should i do to fix this?


These are the methods i use to export to csv:

C#
<pre>private static IEnumerable<string> ToCsv<T>(IEnumerable<T> list)
        {
            var fields = typeof(T).GetFields();
            var properties = typeof(T).GetProperties();

            foreach (var @object in list)
            {
                yield return string.Join(",",
                                         fields.Select(x => (x.GetValue(@object) ?? string.Empty).ToString())
                                               .Concat(properties.Select(p => (p.GetValue(@object, null) ?? string.Empty).ToString()))
                                               .ToArray());
            }
        }

        private void ExportBookDb(string saveFilePath)
        {
            BookDBDataContext bDC = new BookDBDataContext();
            if (ExclBookList != null)
            {
                ExclBookList.Clear();
            }

            ExclBookList = new ObservableCollection<Book>(bDC.Books);
            Book bPropNames = new Book();
           
            using (StreamWriter textWriter = File.CreateText(saveFilePath + ".csv"))
            {
                textWriter.WriteLine(nameof(bPropNames.Id) + "," + nameof(bPropNames.Title) + "," + nameof(bPropNames.Author) + "," + nameof(bPropNames.Isbn) + "," + nameof(bPropNames.Quantity) + "," + nameof(bPropNames.RezervedQty));
                foreach (var line in ToCsv(ExclBookList))
                {                   
                    textWriter.WriteLine(line);
                }
            }


Thank you in advance!
AnswerRe: C# writing to a csv file, adds an extra column Pin
Richard Deeming9-Aug-17 1:08
mveRichard Deeming9-Aug-17 1:08 
GeneralRe: C# writing to a csv file, adds an extra column Pin
Member 128805959-Aug-17 5:23
Member 128805959-Aug-17 5:23 
QuestionHow to implement an existing methods in Visual Studio? Pin
gcobza20105-Aug-17 3:56
gcobza20105-Aug-17 3:56 
AnswerRe: How to implement an existing methods in Visual Studio? Pin
OriginalGriff5-Aug-17 4:40
mveOriginalGriff5-Aug-17 4:40 
AnswerRe: How to implement an existing methods in Visual Studio? Pin
Dave Kreskowiak5-Aug-17 7:11
mveDave Kreskowiak5-Aug-17 7:11 
QuestionWhy do libraries not help me? If I want to write parameter like myapp.exe -param1 <value> -param2 <value> .. Pin
Jens Eckervogt 4-Aug-17 13:53
Jens Eckervogt 4-Aug-17 13:53 
AnswerRe: Why do libraries not help me? If I want to write parameter like myapp.exe -param1 <value> -param2 <value> .. Pin
Richard Andrew x644-Aug-17 14:56
professionalRichard Andrew x644-Aug-17 14:56 
GeneralRe: Why do libraries not help me? If I want to write parameter like myapp.exe -param1 <value> -param2 <value> .. Pin
Jens Eckervogt 4-Aug-17 23:22
Jens Eckervogt 4-Aug-17 23:22 
GeneralRe: Why do libraries not help me? If I want to write parameter like myapp.exe -param1 <value> -param2 <value> .. Pin
PIEBALDconsult4-Aug-17 15:44
mvePIEBALDconsult4-Aug-17 15:44 
GeneralRe: Why do libraries not help me? If I want to write parameter like myapp.exe -param1 <value> -param2 <value> .. Pin
Jens Eckervogt 4-Aug-17 22:44
Jens Eckervogt 4-Aug-17 22:44 
AnswerRe: Why do libraries not help me? If I want to write parameter like myapp.exe -param1 <value> -param2 <value> .. Pin
Richard MacCutchan5-Aug-17 0:10
mveRichard MacCutchan5-Aug-17 0:10 
QuestionC# and the media player Pin
Humberto Mariles3-Aug-17 4:28
Humberto Mariles3-Aug-17 4:28 
AnswerRe: C# and the media player Pin
Pete O'Hanlon3-Aug-17 4:40
mvePete O'Hanlon3-Aug-17 4:40 
AnswerRe: C# and the media player Pin
Luc Pattyn5-Aug-17 10:59
sitebuilderLuc Pattyn5-Aug-17 10:59 
AnswerRe: C# and the media player Pin
BenScharbach12-Aug-17 9:28
BenScharbach12-Aug-17 9:28 
GeneralRe: C# and the media player Pin
Humberto Mariles22-Aug-17 8:26
Humberto Mariles22-Aug-17 8:26 
QuestionTool or style help to manage coding Pin
Kanel Roath2-Aug-17 18:17
Kanel Roath2-Aug-17 18:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.