Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reverse navigation for foreign key
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Entity Framework
Title:
Reverse navigation for foreign key
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01615112
Message ID:
01615112
Views:
39
Hi everybody,

I am wondering is there a way to introduce foreign key without using configuration file?

Right now I have Layouts.cs file with the following code:
 // Foreign keys
        public virtual LayoutTypes LayoutTypes { get; set; } // FK_Layouts_LayoutTypes
and also

LayoutsConfiguration.cs file with the following code:
 // Foreign keys
            HasRequired(a => a.LayoutTypes).WithMany(b => b.Layouts).HasForeignKey(c => c.LTypeId); // FK_Layouts_LayoutTypes
where the configuration class is based on
internal partial class LayoutsConfiguration : EntityTypeConfiguration<Layouts>
Both of these classes are auto-generated.

I added a new view to the database and auto-generated classes for that view. Everything is OK but one of the methods is using the following code
 var query = SearchHelper.GetFilteredSearch<LayoutsList>(_dbSetList.Include("LayoutTypes").AsQueryable(), searchRequest);
            var pagedResultMessage = SearchHelper.GetPagedResult(query, searchRequest);
            return pagedResultMessage;
The original code was based on the Layouts table and model and class and so it worked OK. With that new view LayoutsList I am wondering how can I introduce the LayoutTypes into the picture. I can create a partial class for LayoutsList to have this line of code
<pre>
 // Foreign keys
        public virtual LayoutTypes LayoutTypes { get; set; } // FK_Layouts_LayoutTypes


but I am afraid that would not be enough.

While I was writing this message I thought - may be I just change my view to include some columns from LayoutTypes into the view directly and would not need the include at all this way? I need to look closer as how this is used in our application,
If it's not broken, fix it until it is.


My Blog
Reply
Map
View

Click here to load this message in the networking platform