Unlike many post I've seen online, It's not if I prefer Guid or Int.
Question: I'd like to know HOW to make a Guid for the UserId for the SimpleMembership. If I can't, how to do my own provider code first in order to put, in the end, the UserId in another table (to link a record to the user that did it + I don't want the username (what happens if it changes?)).
My research: I've seen that you would have to subclass and reimplement every methods, but nowhere there was a post that explains how to do it.
The closest post I've seen is : http://www.brianlegg.com/post/2011/05/09/Implementing-your-own-RoleProvider-and-MembershipProvider-in-MVC-3.aspx but it's still with Int as the Identity Pk.
I understand that it may be a feature for VS2012 to do so, but VS2010 does all the tables (User with Guid has Id and all the other tables with Guid columns). I'd still like my UserId with Guid and not int.
Thanks!
I believe you are looking for SimpleGuidMembershipProvider
Related
I have a generic group members table with a GUID for a "group type" and a GUID for "referenced object". An example would be if I have a table of customers(each having a GUID) I can group them under "already paid" by creating a group GUID and in my "Group members table" referencing every customer by their respective GUID. This allows for any type of group to be added to the model as we expand(without adding extra tables).
Here is the problem. I have created a subquery in an entity in order to filter the universal group members table for a certain group and what "items" are and are not in that group; like so:
partial void ElementsNotMemberOfGroup_PreprocessQuery(int? UniversalGroupTypeIDParameter, int? UniversalGroupsIDParameter, ref IQueryable<UniversalGroupMember> query)
{
query = query.Where(x => x.UniversalGroup.UniversalGroupType.UniversalGroupTypeID == UniversalGroupTypeIDParameter);
query = query.Where(x => x.UniversalGroup.UniversalGroupsID != UniversalGroupsIDParameter);
}
This returns the GUIDs for the referenced object in the group, but for a user that's useless. I need to join this table and my customers table at runtime on the GUID so I can extract the customer info and display it.
Any Ideas?
LightSwitch wasn't really created with this kind of scenario in mind. LightSwitch makes things very easy for you when you create relationships between tables that are, well, "related". When you do this, you never need manual joins between entities.
While it's possible to do something similar to what you're describing (see the link below), it's a lot more work to achieve it, and in my opinion it isn't really worth the extra trouble. Not only that, but as you're discovering, it complicates even the most simple operations.
In essence, you're working against LightSwitch, instead of with it. My advice to you would be that if you really must do this type of manual optimization, then LightSwitch may not be the best product for you to use.
Beth Massi has a blog article, Using Different Edit Screens Based on Record Types (Table Inheritance), which isn't exactly what you're doing, but it may give you some ideas if you decide to still use LightSwitch for your project.
I am developing a website using Webmatrix. I have a post page where user can post an item with several fields like item name, description, user name, phone number etc. I take all these values and save the item in database. Alongwith all this data provided by the user, I also save a user id of the user with WebSecurity.CurrentUserId method for that item.
This works well almost everytime. However, on very few occasions, I noticed that user id is stored as "-1" for some items.
I am absolutely clueless and can't figure out why it's happening.
Has someone ever experienced such thing. Or can someone may have clue about this?
I am not certain this will solve your problem but it would not hurt to verify that the current user is also defined within your web security database with WebSecurity.HasUserId property. I would give that a try - let me know what happens.
Hope that does the trick!
I am developing a social networking site like Facebook. I am confused how to create structure for notification table. Should it be separate for each user or a huge one for all-where records added and deleted frequently ?
I have the same problem as you and found this (found this) upon researching where the table structure given is :
id
user_id (int)
activity_type (tinyint)
source_id (int)
parent_id (int)
parent_type (tinyint)
time (datetime but a smaller type like int would be better)
where:
activity_type tells me the type of activity, source_id tells me the record that the activity is related to. So if the activity type means "added favorite" then I know that the source_id refers to the ID of a favorite record.
The parent_id/parent_type are useful for my app - they tell me what the activity is related to. If a book was favorited, then parent_id/parent_type would tell me that the activity relates to a book (type) with a given primary key (id)
I index on (user_id, time) and query for activities that are user_id IN (...friends...) AND time > some-cutoff-point. Ditching the id and choosing a different clustered index might be a good idea - I haven't experimented with that.
Pretty basic stuff, but it works, it's simple, and it is easy to work with as your needs change. Also, if you aren't using MySQL you might be able to do better index-wise.
It also suggested there to use Redis for faster access to the most recent activities.
With Redis in the mix, it might work like this:
Create your MySQL activity record
For each friend of the user who created the activity, push the ID onto their activity list in Redis.
Trim each list to the last X items
Redis is fast and offers a way to pipeline commands across one connection - so pushing an activity out to 1000 friends takes milliseconds.
For a more detailed explanation of what I am talking about, see Redis' Twitter example: http://code.google.com/p/redis/wiki/TwitterAlikeExample
I hope this might help you also
I am using ASP.NET Membership in my MVC3 application.
I have used a PersonId variable to declare relation ship between UserId and PersonId to insert values into a different table which contains all the information of the user who has a particular UserId.
With this it is obvious that a person having certain UserId would have a definite PersonId.
Like membership store certain values in the Cookies I want to Store my PersonId in as well.
How can i do that?
The obvious benefit of this approach is that i would save a Database call because the main thing I am using is PersonId.
I want to know the best and most secure way to do that.
Please suggest.
Thanks
The short answer is that you will want to look at :
http://msdn.microsoft.com/en-us/library/2y3fs9xs(v=vs.85).aspx
ASP.NET Profile Properties Overview
http://www.codeproject.com/Articles/281602/ASP-NET-Profile-Provider
ASP.NET Profile Provider
For integration purposes our users in Dynamics CRM need to have the same GUIDs as in the rest of our environment (several custom web apps built on ASP.NET and SQL Server 2005). But when we try to create a new Dynamics user with a certain GUID, Dynamics just ignores it and creates its own (the pattern of which leads me to believe that it’s using NEWSEQUENTIALID() internally, just as if the user was created through the UI). But for other types (contact for example) Dynamics takes the GUID with no issue.
Am I doing something wrong, or does Dynamics always ignore GUIDs on new user creation?
CrmService service = GetService();
systemuser newUser = new systemuser();
Key newUserId = new Key();
newUserId.Value = new Guid("D630FA8D-A32F-4a37-BFEF-CE36CBA29009");
// The GUID I would like Dynamics to use
newUser.systemuserid = newUserId;
Lookup bu = new Lookup();
bu.Value = new Guid("16B10365-0E18-DF11-B839-005056B60DD4");
// The correct business unit ID. Nothing to see here.
newUser.businessunitid = bu;
newUser.firstname = "John";
newUser.lastname = "Doe";
newUser.domainname = "DOMAIN\\jdoe";
// Valid AD credentials too. Names changed to protect the innocent.
Guid userId = service.Create(newUser);
Console.WriteLine("User created with GUID " + userId.ToString());
// Dynamics creates the user with a completely different GUID. :-(
Edit:
I've now asked this question on Microsoft's CRM forum as well.
I know it is not ideal, but as a workaround you could add a custom attribute to the systemuser entity and store your integration id there.
Without knowing more about your solution I can tell you that you don't need hardcoded quids everywhere like you are trying to do. When I arrived at my current client they were trying to do the same things and it was a serious PITA.
It took me about a day to replace all the code that was using the hardcoded quids for various entities with a simple lookup procedure that gets the entity by whatever key (user name in your case) you want and then get the entity's id from that. No more trying to do something you should be trying to do in the first place.
It took me about a day to replace all the code that was using the hardcoded quids for various entities with a simple lookup procedure that gets the entity by whatever key (user name in your case)
How interesting. You're searchnig John Doe user by 'John','Doe' strings. And what should I do if I got TWO "John Doe" in my company ?