Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LINQ to SQL assign value to class property

Posted on 2010-09-16
5
Medium Priority
?
689 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 64

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

926 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