refreshing generated code from dbml - visual-studio

I've added two new tables to the database.
I've dropped them on the design surface.
My understanding is that it should just automatically generate the design.cs code as a result.
It did, according to my faulty memory, when I added a new table last week, but not this week.
I checked the references in csproj and everything looks OK there.
I tried the RunCustomTool, but that didn't seem to pull anything in to either the DBML or the designer.cs.
No combination of deleting, saving, and re-adding has had any effect.
This is using the MSLinqToSQLGenerator, not SQLMetal
It feels like there is some simple trick I'm missing.
UPDATE: So the problem is with a specific table.
If I add this table, it generates correctly.
CREATE TABLE [dbo].[_LeakageClass](
[id] [int] NOT NULL,
[Class] [nvarchar](25) NOT NULL,
[Description] [nvarchar](50) NOT NULL
CONSTRAINT [PK__LeakageClass] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
If I add this table, it quits working and nothing else generates code from then on.
CREATE TABLE [dbo].[_SeatSize](
[model] [int] NOT NULL,
[ValveSize] [int] NOT NULL,
[SeatSize] [int] NOT NULL,
[Stroke] [int] NOT NULL
CONSTRAINT [PK__SeatSize] PRIMARY KEY CLUSTERED
(
[model] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

It couldn't handle having a field named similar to the table.
CREATE TABLE [dbo].[_SeatSize](
[SeatSize] [int] NOT NULL,
doesn't work.
CREATE TABLE [dbo].[_SeatSize](
[SeatSizer] [int] NOT NULL,
works fine. Note that the underscore prefix on the table isn't enough to make a difference.

Related

How to make Identity use of MVC instead of razor pages in asp.net core 2.2

Since asp.net core 2.1 the MVC is not supported as default model with Identity. I want to run Identity with MVC in asp.net core 2.2
Make a long story short. This is a asp.net 4.6.2 site with local db that I want upgrade to asp.net core 2.2 . I thought that this would be simple thing. So wrong I was. So what did I do:
Created an new ASP.net core 2.0 project with local Identity
Scaffolded the ef context with database first with Scaffold-DbContext
Fixed so EF is loaded correctly in Startup.
Removed aspnetusers, aspnetuserroles, aspnetuserlogin, aspnetroles models from generated scaffold by the Scaffold-Dbcontext
Updated ApplicationDbContext to inherits from IdentityDbContext. ApplicationUser inherits from IdentityUser
After I faked that the migration have been applied, I manually added following columns in aspnetusers
6.1 ConcurrencyStamp
6.2 NormalizedUserName
6.3 NormalizedEmail
6.4 Changed name LockoutEnd? to LockoutEnd
The system builds but still I cant get it to use the Account controller. I have followed the steps in https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2
without no avail. It seems what I do I can't get it to read the mvc controller even after I scaffolded the Identity.
I think the difference in implementations of Identity in asp.net core 2.X Identity is either to high or to narrow regarding earlier implementations.
Included part of my startup
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
// services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddRazorPagesOptions(options =>
{
options.AllowAreas = true;
//options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
//options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
});
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/Account/Login";
options.LogoutPath = $"/Account/Logout";
options.AccessDeniedPath = $"/Account/AccessDenied";
});
// using Microsoft.AspNetCore.Identity.UI.Services;
services.AddSingleton<IEmailSender, EmailSender>();
}
I want to use MVC with Identity Core 2.2 with an old database from Identity .Net.
So any suggestions?
It's not clear what you're doing exactly, but it sounds like you've scaffolded the Identity Razor Pages into your project. If that's the case, those are going to take precedent over your controller, since it's a more physical route.
All the other code looks good. You're using AddIdentity instead of AddDefaultIdentity (so the default UI is not included). Assuming you've actually created an AccountController and your routing is set up correctly, then it should work, as long as you don't have the default UI physically scaffolded into your project.
Recently I have done the same thing. The following might help you. First create equivalent Application tables for all AspNet tables. The MS SQL Server script below will create:
dbo.ApplicationRole
dbo.ApplicationRoleClaim
dbo.ApplicationUser
dbo.ApplicationUserClaim
dbo.ApplicationUserLogin
dbo.ApplicationUserRole
dbo.ApplicationUserToken
Open MS SQL Server Management Studio
Select your database
Start a new query
Run the script below and replace YOUR_DATABASE with the name of your database
Next you should copy the contents of your soon obsolete AspNet tables into the new Application tables. In this process you should also handle the change from datatype nvarchar to int for UserId and RoleId.
USE [YOUR_DATABASE]
GO
/****** Object: Table [dbo].[ApplicationRole] Script Date: 24-May-21 9:44:46 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ApplicationRole](
[Id] [int] NOT NULL,
[Name] [nvarchar](256) NULL,
[NormalizedName] [nvarchar](256) NULL,
[ConcurrencyStamp] [nvarchar](max) NULL,
CONSTRAINT [PK_ApplicationRoles] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[ApplicationRoleClaim] Script Date: 24-May-21 9:44:46 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ApplicationRoleClaim](
[Id] [int] IDENTITY(1,1) NOT NULL,
[RoleId] [int] NOT NULL,
[ClaimType] [nvarchar](max) NULL,
[ClaimValue] [nvarchar](max) NULL,
CONSTRAINT [PK_ApplicationRoleClaims] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[ApplicationUser] Script Date: 24-May-21 9:44:46 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ApplicationUser](
[Id] [int] NOT NULL,
[UserName] [nvarchar](256) NULL,
[NormalizedUserName] [nvarchar](256) NULL,
[Email] [nvarchar](256) NULL,
[NormalizedEmail] [nvarchar](256) NULL,
[EmailConfirmed] [bit] NOT NULL,
[PasswordHash] [nvarchar](max) NULL,
[SecurityStamp] [nvarchar](max) NULL,
[ConcurrencyStamp] [nvarchar](max) NULL,
[PhoneNumber] [nvarchar](max) NULL,
[PhoneNumberConfirmed] [bit] NOT NULL,
[TwoFactorEnabled] [bit] NOT NULL,
[LockoutEnd] [datetimeoffset](7) NULL,
[LockoutEnabled] [bit] NOT NULL,
[AccessFailedCount] [int] NOT NULL,
CONSTRAINT [PK_ApplicationUsers] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[ApplicationUserClaim] Script Date: 24-May-21 9:44:46 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ApplicationUserClaim](
[Id] [int] IDENTITY(1,1) NOT NULL,
[UserId] [int] NOT NULL,
[ClaimType] [nvarchar](max) NULL,
[ClaimValue] [nvarchar](max) NULL,
CONSTRAINT [PK_ApplicationUserClaims] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[ApplicationUserLogin] Script Date: 24-May-21 9:44:46 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ApplicationUserLogin](
[LoginProvider] [nvarchar](128) NOT NULL,
[ProviderKey] [nvarchar](128) NOT NULL,
[ProviderDisplayName] [nvarchar](max) NULL,
[UserId] [int] NOT NULL,
CONSTRAINT [PK_ApplicationUserLogins] PRIMARY KEY CLUSTERED
(
[LoginProvider] ASC,
[ProviderKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[ApplicationUserRole] Script Date: 24-May-21 9:44:46 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ApplicationUserRole](
[UserId] [int] NOT NULL,
[RoleId] [int] NOT NULL,
CONSTRAINT [PK_ApplicationUserRole] PRIMARY KEY CLUSTERED
(
[UserId] ASC,
[RoleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ApplicationUserToken] Script Date: 24-May-21 9:44:46 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ApplicationUserToken](
[UserId] [int] NOT NULL,
[LoginProvider] [nvarchar](128) NOT NULL,
[Name] [nvarchar](128) NOT NULL,
[Value] [nvarchar](max) NULL,
CONSTRAINT [PK_ApplicationUserTokens] PRIMARY KEY CLUSTERED
(
[UserId] ASC,
[LoginProvider] ASC,
[Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[ApplicationRoleClaim] WITH CHECK ADD CONSTRAINT [FK_ApplicationRoleClaims_ApplicationRoles_RoleId] FOREIGN KEY([RoleId])
REFERENCES [dbo].[ApplicationRole] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ApplicationRoleClaim] CHECK CONSTRAINT [FK_ApplicationRoleClaims_ApplicationRoles_RoleId]
GO
ALTER TABLE [dbo].[ApplicationUser] WITH CHECK ADD CONSTRAINT [FK_ApplicationUsers_Club] FOREIGN KEY([ClubId])
REFERENCES [dbo].[Club] ([Id])
GO
ALTER TABLE [dbo].[ApplicationUser] CHECK CONSTRAINT [FK_ApplicationUsers_Club]
GO
ALTER TABLE [dbo].[ApplicationUserClaim] WITH CHECK ADD CONSTRAINT [FK_ApplicationUserClaims_ApplicationUsers_UserId] FOREIGN KEY([UserId])
REFERENCES [dbo].[ApplicationUser] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ApplicationUserClaim] CHECK CONSTRAINT [FK_ApplicationUserClaims_ApplicationUsers_UserId]
GO
ALTER TABLE [dbo].[ApplicationUserLogin] WITH CHECK ADD CONSTRAINT [FK_ApplicationUserLogins_ApplicationUsers_UserId] FOREIGN KEY([UserId])
REFERENCES [dbo].[ApplicationUser] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ApplicationUserLogin] CHECK CONSTRAINT [FK_ApplicationUserLogins_ApplicationUsers_UserId]
GO
ALTER TABLE [dbo].[ApplicationUserRole] WITH CHECK ADD CONSTRAINT [FK_ApplicationUserRole_ApplicationRole] FOREIGN KEY([RoleId])
REFERENCES [dbo].[ApplicationRole] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ApplicationUserRole] CHECK CONSTRAINT [FK_ApplicationUserRole_ApplicationRole]
GO
ALTER TABLE [dbo].[ApplicationUserRole] WITH CHECK ADD CONSTRAINT [FK_ApplicationUserRole_ApplicationUser] FOREIGN KEY([UserId])
REFERENCES [dbo].[ApplicationUser] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ApplicationUserRole] CHECK CONSTRAINT [FK_ApplicationUserRole_ApplicationUser]
GO
ALTER TABLE [dbo].[ApplicationUserToken] WITH CHECK ADD CONSTRAINT [FK_ApplicationUserTokens_ApplicationUsers_UserId] FOREIGN KEY([UserId])
REFERENCES [dbo].[ApplicationUser] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ApplicationUserToken] CHECK CONSTRAINT [FK_ApplicationUserTokens_ApplicationUsers_UserId]
GO

Composite Primary Key having column with Allow Null true

I would like to know the best practice.
I have a table Committee, Application, EmpInternal and EmpExternal
The primary key of Committee is a composite Key comprising of ApplicationID, EmpInternalID and EmpExternalID
Now since, AllowNull property is not allowed to be true in a column in composite key. What should I do to store committee members in Committee table which are sometimes Internal and external. All the columns ApplicationID, EmpInternalID and EmpExternalID are autonumber in their respective tables
CREATE TABLE [dbo].[Employee](
[EmployeeID] [varchar](10) NOT NULL,
[UserID] [varchar](100) NULL,
[Title] [varchar](50) NULL,
[Name] [nvarchar](240) NULL,
[Rank] [varchar](150) NULL,
[Department] [varchar](240) NULL,
[College] [varchar](240) NULL,
[POBox] [varchar](120) NULL,
[Phone] [varchar](60) NULL,
[JoinDate] [varchar](200) NULL,
CONSTRAINT [PK_Employee1] PRIMARY KEY CLUSTERED
(
[EmployeeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY])
CREATE TABLE [dbo].[EmployeeExternal](
[EmployeeExID] [varchar](10) NOT NULL,
[Title] [nvarchar](50) NULL,
[Name] [nvarchar](50) NULL,
[Rank] [nvarchar](50) NULL,
[Department] [nvarchar](4000) NULL,
[Organization] [nvarchar](4000) NULL,
[Address] [nvarchar](4000) NULL,
[Email] [nvarchar](50) NULL,
[Email2] [nvarchar](50) NULL,
[Phone] [nvarchar](50) NULL,
[Mobile] [nvarchar](50) NULL,
[Country] [nvarchar](50) NULL,
CONSTRAINT [PK_Employee1] PRIMARY KEY CLUSTERED
( [EmployeeExID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY])
A flag record in the Employee table and EmployeeExternal table is a better solution than merging these two tables. the key of flagged record in the composite key remove the use of null in the composite key

Linq making primary key system.nullable<int> not just int

I'm mapping my database into base object with Linq to SQL. I drag all the tables into my dbml and they all setup nicely. I save the dbml and it creates the classes that represent the tables, etc.
In my database I have a table as such:
CREATE TABLE [dbo].[BidNames](
[BidNameID] [int] IDENTITY(1,1) NOT NULL,
[CustomerID] [int] NOT NULL,
[BidName] [varchar](75) NOT NULL,
CONSTRAINT [PK_BidNames] PRIMARY KEY CLUSTERED
(
[BidNameID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
The BidNameID field is clearly a primary key and obviously NOT NULL. Linq, however defines BidNameID like this:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_BidNameID", DbType="Int")]
public System.Nullable<int> BidNameID
{
get
{
return this._BidNameID;
}
set
{
if ((this._BidNameID != value))
{
if (this._BidName1.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnBidNameIDChanging(value);
this.SendPropertyChanging();
this._BidNameID = value;
this.SendPropertyChanged("BidNameID");
this.OnBidNameIDChanged();
}
}
}
Where BidNameID is defined as System.Nullable. All the other tables in my database resolve correctly so I'm left wondering why this is happening. Any ideas?
Thanks in advance.
EDIT
I have discovered that this problem is related to another table. If I drop the Bids table from my dbml and re-save, the BidNameID column correctly resolves to int. If I put the Bids table back and save it goes back to Nullable. The Bids table has a foreign key into the BidNames table but the data is clean. Here is the structure of the Bids table:
CREATE TABLE [dbo].[Bids](
[BidID] [int] IDENTITY(1,1) NOT NULL,
[CustomerID] [int] NOT NULL,
[ItemID] [int] NOT NULL,
[Amount] [money] NOT NULL,
[BidName] [varchar](75) NOT NULL,
[BidTime] [datetime] NOT NULL,
[BidNameID] [int] NULL,
CONSTRAINT [PK_Bids] PRIMARY KEY CLUSTERED
(
[BidID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
ALTER TABLE [dbo].[Bids] WITH CHECK ADD CONSTRAINT [FK_Bids_BidNames] FOREIGN KEY([BidNameID])
REFERENCES [dbo].[BidNames] ([BidNameID])
GO
ALTER TABLE [dbo].[Bids] CHECK CONSTRAINT [FK_Bids_BidNames]
GO
ALTER TABLE [dbo].[Bids] WITH CHECK ADD CONSTRAINT [FK_Bids_Customers] FOREIGN KEY([CustomerID])
REFERENCES [dbo].[Customers] ([CustomerID])
GO
ALTER TABLE [dbo].[Bids] CHECK CONSTRAINT [FK_Bids_Customers]
GO
ALTER TABLE [dbo].[Bids] WITH CHECK ADD CONSTRAINT [FK_Bids_Items] FOREIGN KEY([ItemID])
REFERENCES [dbo].[Items] ([ItemID])
GO
ALTER TABLE [dbo].[Bids] CHECK CONSTRAINT [FK_Bids_Items]
GO
I took your table script, ran in my DB and dragged it into a dbml and it didn't generate as nullable (VS2010, VB.NET 4.0):
<Global.System.Data.Linq.Mapping.ColumnAttribute(
Storage:="_BidNameID", AutoSync:=AutoSync.OnInsert,
DbType:="Int NOT NULL IDENTITY", IsPrimaryKey:=True,
IsDbGenerated:=True)>
Public Property BidNameID() As Integer
Get
Return Me._BidNameID
End Get
Set(value As Integer)
If ((Me._BidNameID = value) _
= False) Then
Me.OnBidNameIDChanging(value)
Me.SendPropertyChanging()
Me._BidNameID = value
Me.SendPropertyChanged("BidNameID")
Me.OnBidNameIDChanged()
End If
End Set
End Property
Maybe try one or more of these?
drop/recreate the physical table
delete/recreate your DB connection in Server Explorer
delete/recreate the dbml
manually edit the designer file
create additional datacontext partial class and manually maintain that table/mapping
I don't necessarily understand why but when I alter the Bids table and make the BidNameID field NOT NULL, it fixes the problem with the BidName.BidNameID field. It now resolves to int rather than nullable.

Mapping an entity to more than one table (EF4, WCF RiaServices) - Internationalization

if I understood several other posts correctly it's currently not possible to map an entity to more than one table if they do not share the same primary key.
Is this still true? What I'm wondering is how internationalization should be handled with the db design below and EF.
I've a internationalized db where texts are stored in separate tables.
e.g.
CREATE TABLE Product(
ProductID int IDENTITY(1,1) NOT NULL,
ProductGroupID int NOT NULL,
...
CONSTRAINT PK_Product PRIMARY KEY CLUSTERED
(
ProductID ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY
) ON PRIMARY
CREATE TABLE Product_i18n(
ProductID int NOT NULL,
LanguageID int NOT NULL,
ProductName nvarchar(150) NULL,
Description nvarchar(max) NULL,
...
CONSTRAINT PK_Product_i18n PRIMARY KEY CLUSTERED
(
ProductID ASC,
LanguageID ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY
) ON PRIMARY
So the product consists of two tables. In the table Product the language independent part is stored and in the table Product_i18n the language dependend part is stored.
The two tables are physically linked with a 1:n association, but logically it's a 1:1 association because I always need one language at a certain operation.
Therefore I would like to combine the two tables in a single entity Product which consists of the columns
ProductID
ProductGroupID
LanguageID
ProductName
Description ...
If this would be possible I could keep the internationalized table out of my model to make it more clear.
Is this possible with EF4. Any guidance and experiences with internationalization to solve this issue are welcome.
Thanks a lot
Uwe
I don't know if you are still having the problem, but you can solve it using a view for your products, more accurate, one view for each language.

How to select Values from several tables

my three table structure are :
USE [DB_OrderV2]
GO
/****** Object: Table [dbo].[tblPageInfo] Script Date: 07/24/2010 23:16:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPageInfo](
[Code] [int] IDENTITY(1,1) NOT NULL,
[PageID] [smallint] NOT NULL,
[PageName] [nvarchar](80) NOT NULL,
[Description] [nvarchar](80) NOT NULL,
[Status] [tinyint] NOT NULL,
[CreateUserID] [smallint] NULL,
[CreateDate] [smalldatetime] NULL,
[UpdateUserID] [smallint] NULL,
[UpdateDate] [smalldatetime] NULL,
CONSTRAINT [PK_tblPageInfo] PRIMARY KEY CLUSTERED
(
[PageID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [DB_OrderV2]
GO
/****** Object: Table [dbo].[tblUserType] Script Date: 07/24/2010 23:17:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblUserType](
[Code] [int] IDENTITY(1,1) NOT NULL,
[UserTypeID] [smallint] NOT NULL,
[UserType] [nvarchar](50) NOT NULL,
[Status] [tinyint] NULL,
[CreateUserID] [smallint] NULL,
[CreateDate] [smalldatetime] NULL,
[UpdateUserID] [smallint] NULL,
[UpdateDate] [smalldatetime] NULL,
CONSTRAINT [PK_tblUserType] PRIMARY KEY CLUSTERED
(
[UserTypeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [DB_OrderV2]
GO
/****** Object: Table [dbo].[tblUserInfo] Script Date: 07/24/2010 23:18:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblUserInfo](
[Code] [int] IDENTITY(1,1) NOT NULL,
[UserID] [smallint] NOT NULL,
[UserName] [nvarchar](50) NOT NULL,
[LoginName] [nvarchar](50) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[UserTypeID] [smallint] NOT NULL,
[Status] [tinyint] NOT NULL,
[ActiveDate] [datetime] NULL,
[CreateUserID] [smallint] NULL,
[CreateDate] [smalldatetime] NULL,
[UpdateUserID] [smallint] NULL,
[UpdateDate] [smalldatetime] NULL,
CONSTRAINT [PK_tblUserInfo_1] PRIMARY KEY CLUSTERED
(
[UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Using the above table i need a select query to select several fields .but how ?
query = this.Context.tblUserInfos
.Where(p => p.Status == 1)
.Select(p => new { p.tblUserType.UserTypeID,p.tblUserType.UserType,});
return query;
above LINQ query works well ,but here i need to select UserRoleID from tblUserRole table , and PageName from tblPageInfo table .What to write on above query to select those fields.
Just like in SQL you will want to use a join. So something like
query = from p in Context.tblUserInfos
join u in Context.tblUserRole Where p.UserRoleID equals u.UserRoleID
join n in context.tblPageInfo where p.PageName equals n.PageName
where p.Status == 1
select new {p.tblUserType.UserTypeId, p.tblUserType.UserType, u.UserRoleId, n.PageName};
I wasn't quite able to parse what you were trying to join on from each table, but that should get you started.
Edit
I think I may have gotten my syntax confused.
Straight up Labmda Version
query = Context.tblUserInfos
.Join(Context.tblUserRole, info => info.UserRoleID, user => user.UserRoleID, (info, user) => new {Info = info, User = user})
.Join(Context.tblPageInfo, info2 => info2.PageName, name => name.PageName, (info2, name) => new {Info2 = info2, Name = name})
.Where(p => p.Status == 1)
.Select(p => new { p.tblUserType.UserTypeID,p.tblUserType.UserType, User, Name});
I haven't tested that, but I think that's correct.

Resources