entity-framework

Select value from grandchildren

我的梦境 提交于 2020-01-17 09:49:32
问题 I have the following table structure: I want to select: all TableA entries + the Identifier column from Table C that have: a special value in TableBType ("TableBTypeValue") a special value in TableCType ("TableCTypeValue") The problem that I have is that the linq queries seem to fail when there are TableA entries that have no TableB entry or if there are TableB entries without a TableC (TableBType and TableCType is mandatory so they don't have that problem). With SQL this would not be a big

EF5 Code First (Error cannot be inferred from the usage)

会有一股神秘感。 提交于 2020-01-17 09:25:22
问题 Ok, I have been pulling out my hair because I simply cannot make a many to many relationship. I have the following two models: public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string CompanyName { get; set; } public string FirstName { get; set; } public string Lastname { get; set; } public string EmailAddress { get; set; } public string PhoneNumber { get; set; } public

EF5 Code First (Error cannot be inferred from the usage)

允我心安 提交于 2020-01-17 09:25:13
问题 Ok, I have been pulling out my hair because I simply cannot make a many to many relationship. I have the following two models: public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string CompanyName { get; set; } public string FirstName { get; set; } public string Lastname { get; set; } public string EmailAddress { get; set; } public string PhoneNumber { get; set; } public

Can not create my DbContext in a Unit test

梦想的初衷 提交于 2020-01-17 08:26:24
问题 When I create my TLPContext in a unit test I get an exception at the bottom of this page. I did this in the unit test: DbContext context = new TLPContext(); context.Database.CreateIfNotExists(); Is this not the correct approach? What is wrong with my connection string / provider ? I have followed this: http://www.thereforesystems.com/turn-on-msdtc-windows-7/ but it did not help after a reboot. Thats my app.config file in my unit test project: <?xml version="1.0" encoding="utf-8"?>

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 do I use EntityDatasource (Or LinqDatasource) with a Union clause

戏子无情 提交于 2020-01-17 08:03:11
问题 How do I combine records from two tables in an Entitydatasource control? I have googled it and searched on SO with no luck. The SQL of what I need is SELECT DISTINCT username FROM (SELECT s.username FROM project_stakeholders s UNION SELECT t.username FROM project_team_members t) My entities structure is as follows: project_stakeholders ---------------------- project_stakeholders.record_id (PK) project_stakeholders.username project_stakeholders.project project_stakeholders.project_id (FK)

the specified deps.json does not exist angular2 asp.net core application.

泪湿孤枕 提交于 2020-01-17 07:34:08
问题 I have a database I am trying to scaffold into my angular 2 .net core application. I upgraded to .net core 1.1 followed most steps but I am getting the error the specified deps.json does not exist. This is my project.json { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0", "type": "platform" }, "Microsoft.AspNetCore": "1.1.0", "Microsoft.AspNetCore.Mvc.Core": "1.1.1", "Microsoft.AspNetCore.AngularServices": "1.0.0-*", "Microsoft.AspNetCore.Razor.Tools": { "version": "1.0.0

EF ChangeTracker entity collections count always 0

南楼画角 提交于 2020-01-17 07:28:22
问题 In order to execute some actions for all entities deletions I'm trying to handle it like this: public override int SaveChanges() { var deletedEntities = ChangeTracker.Entries() .Where(p => p.State == EntityState.Deleted).ToList(); foreach (var deletedEntity in deletedEntities) { //((SampleEntity)deletedEntity.Entity).SuperCollection.Count(); } return base.SaveChanges(); } I need to handle some entity collections during the deletion process based on the entity collection properties count, but

Newtonsoft is not serializing navigation property

天涯浪子 提交于 2020-01-17 07:19:44
问题 I have an EF object RetailDocuments . It is related to the DocumentTemplateMaster object via foreign key. Many RetailDocuments can have the same DocumentTemplateMaster . I'm retrieving a List<RetailDocument> and have turned off proxy creation and lazy loading. The referenced DocumentTemplateMaster object is there in the List but not when it is serialized. I've tried a number of solutions I've seen here on SO and other places but for whatever reason, it's not working for me. Here's my code,