question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with stored object viewing on datatable and gridview

See original GitHub issue

My program displayed an unexpected result on gridview: image I want to show all fields of the key value, so please help me. My object:

public class Id
	{  
		public string CallTime { set; get; }  
		public string CallerID { set; get; }  
		public string Destination { set; get; }  
	}  
	class Report  
	{  
		[BsonId]  
		public Id key { set; get; }  
		public string Status { set; get; }  
		.  
		.  
}

Stored

var reports = db.GetCollection<Report>("reports");
foreach (Report rp in lsRe)
	reports.Insert(rp);

Query

var col = db.GetCollection<Report>("reports");
col.Include(x=>x.key.CallTime)
	.Include(x => x.key.CallerID)
	.Include(x => x.key.Destination)
	.FindAll());

Sorry for my bad English, thank you.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
JensSchadroncommented, Aug 3, 2019

@bolner I’m honestly not sure anymore if the screenshot that is being showed is LiteDB Studio or another self-made program. @anh309 Can you confirm?

0reactions
JensSchadroncommented, Aug 3, 2019

@anh309 In any case, you don’t need to do the includes as those are only required when you’re using BsonRefs. What you might want to do is a select after the fetching that projects the data in the format that you want it to be (or override the ToString() method of the class Id, like @bolner already suggested)

class Program
{
    static void Main(string[] args)
    {
        var db = new LiteDatabase(new MemoryStream());
        var col = db.GetCollection<Report>();

        col.Insert(new Report
        {
            Key = new Id
            {
                CallerId = "callerId",
                CallTime = "123",
                Destination = "The other side"
            },
            Status = "Answered"
        });

        var fetchedList = col
            .FindAll()
            .Select(report =>  new {report.Key.CallTime, report.Key.CallerId, report.Key.Destination, report.Status})
            .ToList();
    }

    class Id
    {
        public string CallTime { set; get; }
        public string CallerId { set; get; }
        public string Destination { set; get; }
    }

    class Report
    {
        [BsonId]
        public Id Key { set; get; }

        public string Status { set; get; }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

DataTable to GridView did not display the resulting table
I tried debugging and verified that data are being stored into the DataTable correctly. There is no code on the aspx side, just...
Read more >
Solved: DataTable is showing [object Object] in column for...
Solved: Hi, I have created small App that pulls data from sharepoint list. Form has Datatable and Formviewer to display rows selected in...
Read more >
Insert row into the GridView and not adding the data - MSDN
I store the DataTable in the ViewState so that its contents are not lost, and so I can rebind the DataTable to the...
Read more >
ASPxGridView batch editable column doesn't allow to save ...
Hi, I have an editable Gridview which it's datasource comes from a Datatable I obtain from a sql query. I need to edit...
Read more >
Devexpress gridview get row values. DataTable or System. cre
This method will return an object that represents your data source item. Sorted by: 3. ... GetRowValues and some others (see the ASPxGridView...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found