Tech-Today
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 AspnetUser AspnetUser { get; set; }
}
2.)
[ForeignKey("AspnetUser")]
public Guid UserId { get;set; }
public virtual AspnetUser AspnetUser { get; set; }
-
Specify On Delete No Action Or On Update No Action, Or Modify Other Foreign Key Constraints
Have you encountered this error: "Introducing FOREIGN KEY constraint 'x_y_Target' on table 'z_UsersInRoles' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints."...
-
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...
-
Calling Mssql's Aspnet_membership_createuser Stored Procedure
Here's how you would want to call mssql's aspnet_Membership_CreateUser method: DECLARE @return_value int, @UserId uniqueidentifier, @nowUtc datetime, @now datetime set @nowUtc = getutcdate() set @now = getdate() EXEC @return_value = [dbo].[aspnet_Membership_CreateUser]...
-
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