Solved

LINQ to SQL assign value to class property

Posted on 2010-09-16
5
669 Views
Last Modified: 2013-11-11
Given the database schema below which is my linq dbml model

I need to assign a role to the user partial class.   So I want to say something like

user.rolename  = "temp Role"

I need to implement it like this.....



   public static User TempUser
        {
            get
            {
                return new User() { userName = "Temp",  RoleName = "temp role"  };
            }
        }

How can I do this?
USER
UserID           Int
RoleID           Int
Username         varchar(100)



ROLES
RoleID           int
RoleName         varchar(100)

Open in new window

0
Comment
Question by:ToString1
  • 3
  • 2
5 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 33692991
Hi ToString1;

Don't understand the question, in the below statement User does not have a property name.

user.rolename  = "temp Role"

Do you want an object that contains all User properties as well as rolename returned from a query?

public class UserRole
{
    public int UserID            { get; set; }
    public int RoleID             { get; set; }
    public string Username   { get; set; }
    public string Rolename   { get; set; }
}

Fernando
0
 

Author Comment

by:ToString1
ID: 33693201
Hi

I am implementing custom principle object and want to assign a user a role of "temp role".  

The USER object is related to the ROLES object via roleID

if you look at the code snippet below, in other code I am calling the static property TempUser and assigning it a roleID but I want to check against the role name like this

 bool isAuthenticated = !(userRole.roleName == TempUser.RoleName);
public static User TempUser
        {
            get
            {
                return new User() { userName = "Temp", roleID = (int)UserRoles.TempRole};
            }
        }

 
        #region IPrincipal Members

        public IIdentity Identity
        {
            get
            {
                bool isAuthenticated = !(userRole.roleName == TempUser.userName);
                return new Identity(isAuthenticated, this.userName);
            }
        }

Open in new window

0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 33694048
May be this is what you are looking for.

bool isAuthenticated = !(userRole.roleName == TempUser.ROLES.RoleName);
0
 

Author Comment

by:ToString1
ID: 33695036
HI thanks

But if I try that I get "cannot convert type 'string' to Guest.Role
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 33695737
I am not a ASP .Net developer so don't know much about authentication object hopefully someone else will drop in to help, sorry.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 66
vb.net convert long time to mm:ss 23 20
WPF Select Items 3 24
insert an Jpeg/bmp image onto the visio drawing using VBA/C# 5 19
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question