Solved

LINQ to SQL assign value to class property

Posted on 2010-09-16
5
666 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 62

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 62

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 62

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Limiting string to two deciamls 18 32
Chat Room 1 28
Asp.net mvc 5 5 19
Format column on datatable 7 17
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now