EasyCFM.COM ColdFusion Forums / .NET to CFML / Need to understand asp.net code for coldfusion

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Need to understand asp.net code for coldfusion

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

gavy
08-10-2009 @ 7:49 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 72
Joined: Feb 2005

Hi Guys i have the following which i am having difficulty in understanding:

Please Guide me, if u people can explain me in detail. That will be nice of You:

public List<Friend> GetFriendsByAccountID(Int32 AccountID)
{
List<Friend> result = new List<Friend>();
using(FisharooDataContext dc = conn.GetContext())
{
//Get my friends direct relationship
IEnumerable<Friend> friends = (from f in dc.Friends
where f.AccountID == AccountID
&&
f.MyFriendsAccountID AccountID
select f).Distinct();
result = friends.ToList();
//Getmy friends indirect relationship
var friends2 = (from f in dc.Friends
where f.MyFriendsAccountID == AccountID &&
f.AccountID != AccountID
select new
{
FriendID = f.FriendID,
AccountID = f.MyFriendsAccountID,
MyFriendsAccountID = f.AccountID,
CreateDate = f.CreateDate,
Timestamp = f.Timestamp
}).Distinct();
foreach (object o in friends2)
{
Friend friend = o as Friend;
if(friend != null)
result.Add(friend);
}
}
return result;
}


<< << ArrowHead >> >>

<cf_bitterhead>
I Changed My Signature Coldfusion + Fusebox Started
</cf_bitterhead>

This message was edited by gavy on 8-10-09 @ 8:51 PM

nmiller
08-11-2009 @ 8:19 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 773
Joined: Apr 2003

This is a method that takes an AccountID as an input and runs
two LINQ queries to get lists of friends, and then combines them
and returns the result.

If you wrote this in CF it might look something like


<cffunction name="GetFriendsByAccountID" output="false"
returntype="query">

<cfargument name="AccountID" type="numeric" required="true">
<cfset var result = "">
<cfset var directFriends = "">
<cfset var indirectFriends = "">

<cfquery name="directFriends" datasource="Fisharoo">
select distinct FriendID, AccountID,
MyFriendsAccountID, CreateDate,Timestamp
From [tables here]
where accountid = #arguments.accountid#
</cfquery>

<cfquery name="indirectFriends" datasource="Fisharoo">
select distinct FriendID, AccountID,
MyFriendsAccountID, CreateDate,Timestamp
From [tables here]
where MyFriendsAccountID = #arguments.AccountID#
and AccountID != #arguments.AccountID#
</cfquery>

<cfquery name="result" dbtype="query">
select * from directFriends
UNION
select * from indirectFriends
</cfquery>

<cfreturn result />
</cffunction>




Nathan Miller
NM Consulting


Website Designed and Developed by Pablo Varando.