Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reverse navigation for foreign key
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Titre:
Reverse navigation for foreign key
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01615112
Message ID:
01615112
Vues:
38
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
Répondre
Fil
Voir

Click here to load this message in the networking platform