Using a .net method while getting data from bucket view


#1

Hello everyone,

I created 3 different bucket views and now I’m using them like follows:

        var myBucket = myCluster.OpenBucket();
        var querymain = myBucket.CreateQuery("dev_default", "view_default");
        var querypop = myBucket.CreateQuery("dev_default", "view_popular");
        var querynew = myBucket.CreateQuery("dev_default", "view_newest");
        var result = myBucket.Query<dynamic>(querymain);
        var result2 = myBucket.Query<dynamic>(querypop);
        var result3 = myBucket.Query<dynamic>(querynew);


        Response.Clear();


        Response.Write("{ \"HasError\":false,\"Data\":{ \"PopularForums\":[");
        foreach (var row2 in result2.Rows)
        {

          Response.Write(row2.Value);
            if (row2 != result2.Rows.ToList().Last())
                Response.Write(",");
        }
        Response.Write("],");


        Response.Write("\"NewestForums\":[");
        foreach (var row3 in result3.Rows)
        {
            Response.Write(row3.Value);
            if (row3 != result3.Rows.ToList().Last())
                Response.Write(",");
        }
        Response.Write("],");


        Response.Write("\"MainForums\":[");
        foreach (var row in result.Rows)
        {
            Response.Write(row.Value);
            if (row != result.Rows.ToList().Last())
                Response.Write(",");
        }
        Response.Write("]}}");

        Response.End();

I formatted it to make it a proper JSON data. But I have a problem. result.Rows is lists of properties like that :

{
Id: 12,
Title: "Konu Dışı",
Description: "Her şey , hayat, şu, bu, vs",
Parent: 0,
HasChild: false,
Level: 1,
ImageUrl: "http://icon.donanimhaber.com/mobile-forum-icons/12.png",
AvarageColor: null,
RepMode: 0,
MessageCountThisWeek: 30076,
TopicCountThisWeek: 1826
},

I am getting all the data above from couchbase, but I need to use a method I just wrote in .net to get “AvarageColor”. The method needs a data called “iconPath” that is in my couchbase to find the AvarageColor.

How can I do that? I hope I could explain it.

Thanks!


#2

I’m not sure I understand this part. If it’s in a separate document, you can just fetch that document. With traditional databases you’re probably used to working in larger chunks since there is IO and transaction overhead in getting the data. If you have a way to refer to the other doc, you can just fetch it.


#3

@ingenthr Hi,
No it is not in another document, I have a method called “GetColor()” on my .net project and to find average color I have to call it like GetColor(iconPath);

iconPath is in the document, but I can’t call GetColor() in my bucket’s view so I need to do the method calling part on my .net project. But as you see I’m getting all the data in that foreach block and I don’t know how am I gonna add this function somewhere between there and find “iconPath” property.


#4

@HandeBc -

Is your project an MVC or WebForms? I see your using the “rawer” ASP.NET API’s and writing directly to the response buffer…usually it’s advised to use the higher level abstractions - e.g. Code Behind or Controllers. That being said, you’ll need just need to write a method and call it, something like this:

public object GetColor(string iconPath)
{
    //do something
}

//later in your code
var color = GetColor(iconPath);

//use color variable or whatever 

-Jeff