Link to home
Start Free TrialLog in
Avatar of ToString1
ToString1

asked on

LINQ to SQL assign value to class property

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

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

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
Avatar of ToString1
ToString1

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HI thanks

But if I try that I get "cannot convert type 'string' to Guest.Role
I am not a ASP .Net developer so don't know much about authentication object hopefully someone else will drop in to help, sorry.