Can you use an in-line method like this in C#?

Can you do this in C#?

FKCreatedBy = (aspnet_Membership.Key != null ? aspnet_Membership.Key :
GetGuestGuid());

(this is the method GetGuestGuid)

        public static Guid GetGuestGuid()
        {
            // Guest is declared as a private const elsewhere
            aspnet_Membership am = aspnet_Membership.GetUser(Guest);
            return am.UserId;
        }

When I run the code in debug mode I can see that it's returning a GUID
in return am.UserId, but this is never assigned to FKCreatedBy.

Thoughts?

Thanks

Edward
0
Edward
12/22/2009 12:11:50 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

6 Replies
522 Views

Similar Articles

[PageSpeed] 23

And this FKCreatedBy line is called from ? My guess is that this line is 
never executed...

The issue is still a bit unclear as the terminology seems a bit confusing 
but you could just expose this the exact same way you exposed GetGuestGuid 
and it should be fine... Else where is your FKCreatedBy statement ? (for now 
it would appears to me you are trying to use this like a macro ???)



--
Patrice


"Edward" <teddysnips@hotmail.com> a �crit dans le message de 
news:b5d93ca2-8dfe-4137-bdfa-407b90ffd5df@j19g2000yqk.googlegroups.com...
> Can you do this in C#?
>
> FKCreatedBy = (aspnet_Membership.Key != null ? aspnet_Membership.Key :
> GetGuestGuid());
>
> (this is the method GetGuestGuid)
>
>        public static Guid GetGuestGuid()
>        {
>            // Guest is declared as a private const elsewhere
>            aspnet_Membership am = aspnet_Membership.GetUser(Guest);
>            return am.UserId;
>        }
>
> When I run the code in debug mode I can see that it's returning a GUID
> in return am.UserId, but this is never assigned to FKCreatedBy.
>
> Thoughts?
>
> Thanks
>
> Edward 

0
Patrice
12/22/2009 1:46:05 PM
"Edward" <teddysnips@hotmail.com> wrote in message 
news:b5d93ca2-8dfe-4137-bdfa-407b90ffd5df@j19g2000yqk.googlegroups.com...

> Can you do this in C#?

The overall syntax is valid, though "purists" will doubtless throw up their 
arms in despair... ;-)


> When I run the code in debug mode I can see that it's returning a GUID
> in return am.UserId, but this is never assigned to FKCreatedBy.
>
> Thoughts?

Pull it to pieces and step through it - you'll soon see where the problem 
is:

if (aspnet_Membership.Key != null)
{
    FKCreatedBy = aspnet_Membership.Key;
}
else
{
    FKCreatedBy = GetGuestGuid();
}

How is FKCreatedBy defined...?


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net 

0
Mark
12/22/2009 1:49:17 PM
On Dec 22, 1:49=A0pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "Edward" <teddysn...@hotmail.com> wrote in message
>
> news:b5d93ca2-8dfe-4137-bdfa-407b90ffd5df@j19g2000yqk.googlegroups.com...
>
> > Can you do this in C#?
>
> The overall syntax is valid, though "purists" will doubtless throw up the=
ir
> arms in despair... ;-)

Why?  It's quite economical.

> > When I run the code in debug mode I can see that it's returning a GUID
> > in return am.UserId, but this is never assigned to FKCreatedBy.
>
> > Thoughts?
>
> Pull it to pieces and step through it - you'll soon see where the problem
> is:
>
> if (aspnet_Membership.Key !=3D null)
> {
> =A0 =A0 FKCreatedBy =3D aspnet_Membership.Key;}
>
> else
> {
> =A0 =A0 FKCreatedBy =3D GetGuestGuid();
>
> }
>
> How is FKCreatedBy defined...?

It's a column in a Linq mapping, used thus in the Submit from a record
entry form:

public void Submit(Customers record)
{
    bool IsNewRecord =3D record.CustomersID =3D=3D 0;

    SalesPortalDataContext dc =3D new SalesPortalDataContext
();
    Customer rec;
    if (!IsNewRecord)
    {
	rec =3D dc.Customers.FirstOrDefault(p =3D> p.CustomersID =3D=3D
record.CustomersID);
    }
    else
    {
	rec =3D new Customer
	{
	    FKCreatedBy =3D (aspnet_Membership.Key !=3D null ?
aspnet_Membership.Key : GetGuestGuid()),
	    Created =3D DateTime.Now
	};
etc.

0
Edward
12/22/2009 2:12:28 PM
On Dec 22, 2:12=A0pm, Edward <teddysn...@hotmail.com> wrote:

This just in;

Guid temp =3D (Guid)(aspnet_Membership.Key !=3D null ?
aspnet_Membership.Key : GetGuestGuid());

The variable temp contains the correct value when the code is
executed.

Don't understand.

Edward
0
Edward
12/22/2009 2:37:30 PM
And what if you try this exact same code before creating a new customer 
instance (using the temp Guid you just got)  and step through the code ?

It would allow to see if you properly read the guid. Could it be that this 
value is properly initalized but later modified ?

--
Patrice


"Edward" <teddysnips@hotmail.com> a �crit dans le message de 
news:4dd15a7e-0ebc-46da-a92d-50219b0a8c24@a21g2000yqc.googlegroups.com...
On Dec 22, 2:12 pm, Edward <teddysn...@hotmail.com> wrote:

This just in;

Guid temp = (Guid)(aspnet_Membership.Key != null ?
aspnet_Membership.Key : GetGuestGuid());

The variable temp contains the correct value when the code is
executed.

Don't understand.

Edward 

0
Patrice
12/22/2009 2:57:02 PM
On Dec 22, 2:57=A0pm, "Patrice" <http://scribe-en.blogspot.com/> wrote:
> And what if you try this exact same code before creating a new customer
> instance (using the temp Guid you just got) =A0and step through the code =
?
>
> It would allow to see if you properly read the guid. Could it be that thi=
s
> value is properly initalized but later modified ?

Ah.  Hangs head in shame.  Sorry.  Hadn't noticed that, for some
reason, the person who wrote the code, not content with initialising
the record with FKCreatedBy in the constructor, also explicitly set it
later in the code.

Thanks everyone.

Edward
0
Edward
12/22/2009 3:35:09 PM
Reply:

Similar Artilces:

Formatting a single grid line
Don't laugh but I was wondering if there was a back door way of bolding up a single horizontal gridline to make it stand out from the rest. My alternative is to draw a line on the chart but then I need to adjust it if my scale changes. Thanks much, Reney Hi Reney, Unfortunately you can only format all of the gridlines at once. Have a look at these examples for adding a line to a chart. http://peltiertech.com/Excel/Charts/AddLine.html http://tushar-mehta.com/excel/charts/straight_lines/index.html http://www.andypope.info/charts/averageline.htm Cheers Andy Reney Langlois wrote:...

Can't see 401(k) contribiltion total
I've set up a 401(k)accont. I transfer contribiltions to this 401(k)account from each paycheck. When I go to the 401 (k) account view, it shows all the informations such as transections and the account vallue ect., EXCEPT the total contribiltion. I want to know not only what my 401(k) vallue is, but how much money I have contribilt total or over a period of time as well. I find no place to see it. Anybody can help? I'm using Money2002 and 2004 Trial Verstion. Thanks a lot! ...

How can I print a selection in Outlook 2003?
How can I print just a selection of an email in Outlook 2003? The printer driver window is different from the one that comes up in Outlook Express. Thank you! You can do this for HTML formatted messages. Highlight your text, File-> Print... and select to print only the selection -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "Murphie" <Murphie@discussions.microsoft.com> wrote in message news:92F39B50-B877-408A-AAA7-DF350B1D72ED@microsoft.com....

error: OBE-15502 Can only have 16000 per document
Hi, I tried to export data from oracle query builder to Excel sheet, got a error message: OBE-15502 Can only have 16000 per document Is there any way i can get more records(over 16000 or unlimited) in one sheet? thanks. -- JJ ...

Make table truncates text concatenated using fnConcatenate
I have a MakeTable query which uses the fnConcatenate( ) function to merge a bunch of information into a single field. Unfortunately, the field length exceeds 255 characters and the MakeTable tries to dump this into a text field, rather than identifying that the field should be a memo field. I know I could create the base table and import the data from my query into that table, but I would prefer to make this table on the fly, and then delete it when I am done with it. Any recommendations? -- Email address is not valid. Please reply to newsgroup only. On Wed, 11 Apr 2007 12:48:04 -07...

Can't send/receive
anyone have a situation where all of sudden they can't send new messages or receive anything? I get a message when I click on "accounts" that says 'fatal error in outlook unable to complete operation" ...

Sending/exporting Outlook Contacts for use in another computer
I want to send the Outlook Contacts address book from my desktop to use in my laptop. Can it be as simple as copying the whole address book file and replacing the laptop Contacts address book with the new one? Thanks. Bob There is no separate "address book" file. The file you need is your Personal Folders file (*.pst) It's where all the mail, calendar, contacts etc are stored. Take a look at these pages for info on Outlook data backup or transfer: http://www.slipstick.com/config/backup.htm http://www.howto-outlook.com/Howto/backupandrestore.htm http://office.microsoft.com...

Can different editions of Publisher be used together?
If my son uses Publisher 2003 on a school computer, downloads his work to a flash drive, brings it home to edit on Publisher 2007, will he then be able to take the edited work back to the school computer to be used, or will it not be compatible? Stateparent wrote: > If my son uses Publisher 2003 on a school computer, downloads his work to a > flash drive, brings it home to edit on Publisher 2007, will he then be able > to take the edited work back to the school computer to be used, or will it > not be compatible? Publisher 2003 and 2007 share a common file format, so the sc...

Can not Customize Leads View
Hi I have tried to customize the Leads view, I tried to add a view and add some columns to it. The view is shown however I see only the name column. When I go back to the View customization, I see the columns I added. Published your customizations??? -- ---------------------- regards, Ilya Milshtein MBS Master, MBSCP, MCP Softline International www.softline.ru "alsap" wrote: > Hi I have tried to customize the Leads view, I tried to add a view and add > some columns to it. > The view is shown however I see only the name column. > When I go back to the View customi...

Can I change the "Applied Task Update Requests and Errors" view?
I really like this view in PWA 2007, but I would like to replace one column with another. Is this view customizeable? Randy -- Bad news, my friend. This view is not customizable, nor is the view shown in the Task Updates customizable (which many users wish it was). Hope this help. -- Dale A. Howard [MVP] VP of Educational Services msProjectExperts http://www.msprojectexperts.com http://www.projectserverexperts.com "We write the books on Project Server" "Randy Schmid" <RandySchmid@discussions.microsoft.com> wrote in message news:72FA34B5-...

Should be an easy but I can not figure it out!!
I have a text box where the user enters a date and it is assigned to variable txtDate. How to I convert that to the serial number of the date? Thanks for the help IIRC, you can use DATEVAL(String) to get the serial date. -- HTH, Barb Reinhardt "VinceW" wrote: > I have a text box where the user enters a date and it is assigned to variable > txtDate. How to I convert that to the serial number of the date? > > Thanks for the help Barb, Thanks for the quick reply, however I get the error "Sub or Function not defined" when trying...

Bulk attachments
I have a very long list of Images in a single folder that I want to attach to seperate fields in a table/form. Each record contains two images, which are named like this: W:\Foldername\Micromap Run 001 A.bmp =(1st record) W:\Foldername\Micromap Run 001 B.bmp =(1st record) W:\Foldername\Micromap Run 002 A.bmp =(2nd record) W:\Foldername\Micromap Run 002 B.bmp =(2nd record) W:\Foldername\Micromap Run 003 A.bmp =(3rd record) W:\Foldername\Micromap Run 003 B.bmp =(3rd record) and so on... Image A goes to field A Image B goes to field B Is there a way of doing this au...

can't uninstall exchange from cluster nodes
hi our client has several exchange clusters, and one of them is being retired. we have removed the exchange resources and the EVS and the server no longer appears in the organization and everything else there seems to be ok. we can't seem to uninstall exchange from either of the nodes. setup will start saying it's loading components then terminates with no error; happens on both nodes. both nodes are exchange 2003 sp1 on windows 2003. i did find the setup log; here is what it says, hope someone can shed some light on this (company info replaced with < >): [19:47:23] *...

CListCtrl
Hi, Does anybody know an easy of removing the black vertical tracking line that appears while resizing columns? I've been trying to prevent it through HDN_ENDTRACK / HDN_TRACK, but I wasn't successfull. Is there a specific flag that I can set to disable it instead? Thanks in advance for your time, Best regards, -Onur I can't imagine why you'd want to do that, but here's my suggestion: Override the CListrCtrl and CHeaderCtrl class, and have your listview control use your derived header control. In the header control class, handle the WM_SETCURSOR message and load a d...

Can't delete email #2
I'm am trying to help a friend who is using Outlook Express on W98, I cannot delete any messages from her in box. She has over 500 in there, which may be part of the problem. Any suggestions? Desperate! Mark Mark Ryan <m.ryan@earthlink.com> wrote: > I'm am trying to help a friend who is using Outlook Express > on W98, I cannot delete any messages from her in box. She > has over 500 in there, which may be part of the problem. > Any suggestions? The first suggestion is to ask in an Outlok Express newsgroup. The second suggestion is to delete Deleted Items.dbx and ...

Can Not Reply To Emails
Running Windows 7 Professional with latest version of WLM. I get email messages I can not reply to. The reply button is grayed out. For now I am forwarding them to my WinXP computer and then replying from that computer with OE6. Anybody have any ideas? -- <Bill> Brought to you from Anchorage, Alaska. The most obvious reason for not having an active Reply button is not having a mail account set up. --=20 Gary VanderMolen, Microsoft MVP (Mail) http://mvp.support.microsoft.com/default.aspx/profile/vandermolen "Bill Bradshaw" <bradshaw@gci.net>...

Chart line is discontinuous
Hello, A similar problem to my last. I have entered data from reading sheets and not every date/time has a data point. I have noticed that if there is no date/time the chart does not draw the line between data points. Please help me out with this. You can set your chart options (Tools, Options, Chart tab) to treat empty cells as not plotted (leave gaps) zero or interpolated. -- Steve "Lady Excel" <LadyExcel@discussions.microsoft.com> wrote in message news:1F7136D3-3B22-49B9-AFC7-E6BB1FE47E32@microsoft.com... > Hello, > > A similar problem to my last. I have e...

How can I rename a database table?
Hi I am working on a project that uses the MFC CDatabase and CRecordset classes to handle its interfacing with an Access database. It is necessary for the software to rename a table within existing user databases to ensure that they are valid for use with the new version of the software. As a result of my limited database and MFC knowledge I am having difficulty finding a way of renaming the table. I have tried using the following: try { theDataBase.ExecuteSQL( "RENAME oldTableName TO newTableName"); } catch( CDBException* e) { e->m_strError; } However, it results in th...

how can I restore unsaved changes in excel #2
...

Can (or how can) I do this
Hello, My Access application tracks an employee's progress through a process similar to hiring. There are 5 steps in the process. I track 4 of the steps by counting the number of times a value appears in a date field for that step. The count is then displayed and used in a calculation. The 5th step is more complicated. The 5th step needs to determine if the employee has verified that he can access all the applications that he should have access to. My process tracking table has the first 4 dates. The application access info comes from a different table. This process trackin...

Can Not Connect to Exchange Server after Mailbox Move
I have 2 exchange servers. While logged into the domain, and at the location, I can log into the email system just fine. While remote VPN in, I can not access the server. I can ping the server, I can see all shares, and I can even access the printer and print from the exchange server. But I can not get to it with email. Any Ideas? Oh.. both exchange 5.5, both in the same site. Exchange Admin shows both sites just fine. is there a firewall with rules configured, in between the users vpn connection and the internal network? kmelillo@gmail.com wrote: > Oh.. both exchange 5.5, bot...

How do i convert excel to csv in command line? ( not save as)
I am trying to automate a system which needs the files in csv format. Is there any way to convert excel to csv in command line, instead of the usual 'save as'? PS: If you know any UNIX utilities too, please mention. F1, No way I can think of from the command line. You could write an Excel macro that controls the whole process. Open a file, save as csv, close, next file, loop. -- Earl Kiosterud mvpearl omitthisword at verizon period net ------------------------------------------- "F1" <F1@discussions.microsoft.com> wrote in message news:B67ACCB6-CC54-4B5E-...

Can not archive
I get the message "Error while archiving folder "Deleted Items" in store "mailbox-user name." Some items could not be copied. They were either moved or deleted, or access was denied. This only happend recently and only occurs with the deleted items. I can archive send and the inbox without a problem. Any suggestions? Thanks ...

can'not set or connect to an email account
This is a multi-part message in MIME format. ------=_NextPart_000_0010_01CAAC2C.BBDF6A00 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0011_01CAAC2C.BBDF9110" ------=_NextPart_001_0011_01CAAC2C.BBDF9110 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable I am triying to set an email account.I am vodafone mobile customer.Some = settings bloking my access to email service.I am not a professinal = computer user,following the the instractions but no luck.Can you help = me? Thank you. ------=_Nex...

Running simple business using office
Hi, I'm a student and have begun selling some books on amazon. I wanted to develop my business process skills so see it as running a small business. I want to use office to store my 'inventory,' transactions, generate simple invoices and perform some simple analysis e.g. how much i made in a month. (I have student edition with excel and word) I want to keep one data source from which I can perform these tasks. I've got a lot of programming experience but its more from a business process perspective i'm interested. e.g. the best way to store and manipulate the data. I would ...