Tech-Today
Executing a linq query with a bridge table like aspnet_Users and aspnet_Roles
Using model first approach, we add aspnet_Users, aspnet_Roles and aspnet_UsersInRoles in the edmx file. But why is aspnet_UsersInRoles missing? It's because aspnet_Users has one-to-many relationship to aspnet_Roles. To get the role of the user, we need to execute the linq statement below.
class Person {
public string UserName { get; set; }
public string RoleName { get; set;
}
from a in _a2REntities.aspnet_Users
select new Person {
Name = a.Username,
RoleName = a.aspnet_Roles.Select(p=>p.RoleName).FirstOrDefault()
}
-
Deploy A Javaee6 War In Tomcat7 Using Maven
Recently, I'm trying to deploy a simple web application (war) in tomcat7 but it seems the old maven way of deploying a war will not work on it. The plugin I used to use for tomcat6 is: <plugin> <groupId>org.codehaus.mojo</groupId>...
-
Many To Many Relationship In Entity Framework
An example of many-to-many relationship is asp's membership tables, between aspnet_Users and aspnet_Roles. Usually we declare it like this: public class AspUser { public Guid UserId { get; set; } ... public ICollection AspRoles { get; set; } }...
-
How To Declare Foreign Key In Entity Framework
There are 2 ways to declare foreign key in entity framework. Assuming we have 2 entities aspnet_Users and Person, which are link via UserId from aspnet_Users. 1.) class Person { public Guid UserId { get;set; } [ForeignKey("UserId")] public virtual...
-
How To Write Left Join Sql On Entity Framework
In every limitation there is always a work around. For this specific limitation on entity framework 3.5 not having a left join. This is what I came up: For example you want to: SQL: select * from contact a left join country c on a.contactid=c.contactid...
-
Entity Framework Inserting Or Updating A Table With Foreign Key
For example you have 2 lookup entities: Country and Province And Your Person Entity has country and province field. In short both CountryId and ProvinceId are foreign keys to Person table. How to setup the Insert Statement (Update is almost the same,...
Tech-Today