entity-framework-6

How to define matching column in InverseProperty

守給你的承諾、 提交于 2020-01-17 08:11:09
问题 In my MVC application, I have an entity relation between Student and Lookup tables with StatusID-LookupKey and GenderID-LookupKey pairs inestead of (StatusID-ID and GenderID-ID pairs). However, not being able to define the LookupKey column as the matching parameter with the StatusID and GenderID, I have to use ID column of Lookup table. How can I use InverseProperty and match the related columns to the LookupKey column? Thanks in advance. Here are the Lookup table and the entities below:

Struggling with EF's Execute Commands to get the newest ID after an insert

社会主义新天地 提交于 2020-01-17 08:09:10
问题 I am issuing an Insert statement directly against the DB (SQL Server 2008), using EF6.1 on ASP.NET 4.5. I need to get the newest ID in the transaction post insert, however I cannot quite figure out the code. This is what I have at present: db.ExecuteStoreCommand("INSERT INTO Order ([SupplierId]) Values ({0})", SID); Int32 intId = db.ExecuteStoreQuery<Int32>("SELECT SCOPE_IDENTITY()").First(); var myOrder = db.Order.First(r => r.Id == intId); The above example is simplified. Is it possible

How to Exclude Certain Columns in EF6 Using Database First? [duplicate]

混江龙づ霸主 提交于 2020-01-17 06:02:33
问题 This question already has answers here : Entity Framework: Ignore Columns (6 answers) How do you update an edmx file with database changes? (6 answers) Closed 3 years ago . I am working on a project which has a fairly complex database, and the code is stop-gap while another system overhaul is underway. I am fixing up some legacy code, and need to perform work quickly and use work-arounds wherever possible. There is an existing database and I am using EF6 Datbase First with much success.

How to Exclude Certain Columns in EF6 Using Database First? [duplicate]

删除回忆录丶 提交于 2020-01-17 06:02:12
问题 This question already has answers here : Entity Framework: Ignore Columns (6 answers) How do you update an edmx file with database changes? (6 answers) Closed 3 years ago . I am working on a project which has a fairly complex database, and the code is stop-gap while another system overhaul is underway. I am fixing up some legacy code, and need to perform work quickly and use work-arounds wherever possible. There is an existing database and I am using EF6 Datbase First with much success.

Checking property of EF6 model to see if it has a value or not?

不问归期 提交于 2020-01-17 01:39:07
问题 I am trying to figure out how to check a property of my EF 6 model to see if it contains a value or not. The property is an INt64 so I can't use string.Empty and I can not just compare it to an empty string with out converting it. How can I modify this check so it will return "No" if there is no value in "LogoFileID"? HasLogo = (section.LogoFileID != string.Empty) ? "Yes" : "No"; Here is my model public class Section { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Int16 ID {

Adding new child records to a parent table in entity framework 6

痴心易碎 提交于 2020-01-16 22:23:24
问题 I have 3 tables: Account: Id, Name User: Id, AccountId, Name UserDetail: Id, UserId, Phone Entitites: public partial class Account { public Account() { this.Users = new HashSet<User>(); } public int Id{get;set;} public string Name{get;set;} public virtual ICollection<User> Users{get;set;} } public partial class UserDetail { public int Id{get;set;} public string Phone {get;set;} public virual User User {get;set;} } public partial class User { public User() { this.Accounts = new HashSet<Account

PopUp not sending data in database in ASP.NET MVC 5 and Entity Framework

和自甴很熟 提交于 2020-01-16 10:09:12
问题 The popup code works just fine but after I add the credentials and click on the submit button to create the record nothing happens. I'm new to ASP.NET MVC 5 and Entity Framework 6. Any guidance will be most appreciated. @model IEnumerable <LogInTest1.Models.Credentials> @{var createModel = new LogInTest1.Models.Credentials();} @* I think I didn't do this part right *@ @{ ViewBag.Title = "Index"; } Here is the button code: <button class="btn btn-default" onclick="AddData()">Click to Create »<

Looping through tables in Entity Framework 6

徘徊边缘 提交于 2020-01-16 06:28:49
问题 sorry for the simple question. I'm new at this. I have an entity model with several tables and I'd like to get a list of the tables, then I'd like to get the contents of a column from the tables. For example, I have tables of subjects: Biology, Chemistry and Physics, each with a column className (among other columns). I'd like to loop through the tables, get the name then get the contents under that column since I need to ToList() it. I want to do something like this: for each (table in

Can EF6 generate my model objects from a ref cursor returned by an oracle stored procedure

让人想犯罪 __ 提交于 2020-01-16 05:47:05
问题 Can EF6 generate my model objects from a ref cursor returned by an oracle stored procedure?? So my current workplace is in the middle of a switch from using webforms to MVC5. We would like to use EF6 and Oracle stored procedures. A lot of the models that we want to implement will be selecting data from multiple tables(our database is massive). We already have some stored procedures already as well. I either need to be able to tell EF6 to map my models to the results of a stored procedure or

Entity Framework 6 Code First on SQL Server: Map “bool” to “numeric(1,0)” instead of “bit”

北城以北 提交于 2020-01-15 10:26:09
问题 Forward warning #0: upgrading to EF core is not an option in the near future. Forward warning #1: I can't change the column type to bit because this could potentially break legacy VB apps that employ the very same db I'm developing a new app for. Forward warning #2: I also can't employ the int property ==> hidden bool property approach because the very same model needs to work when targeting an Oracle database (in Oracle decimal(1,0) does indeed get mapped to bool without issues - I need to