entity-framework

Entity framework and Exists clause

↘锁芯ラ 提交于 2020-01-11 08:11:08
问题 I'm a rookies of EF so, sorry for my perhaps foolish question. I've 2 entities without any relationship (VS does not load the join and I can't manually add it because the primary key of the child uses a derivated key of its parent). Example Entity master Products keys GKey_K, Product_K fields ..... Entity detail GenericInformation keys GKey_K, GI_K fields Product_K, .... Well, my question is simple (I hope also my english!), how I can read only the products that have some reference on

Entity framework and Exists clause

只愿长相守 提交于 2020-01-11 08:11:07
问题 I'm a rookies of EF so, sorry for my perhaps foolish question. I've 2 entities without any relationship (VS does not load the join and I can't manually add it because the primary key of the child uses a derivated key of its parent). Example Entity master Products keys GKey_K, Product_K fields ..... Entity detail GenericInformation keys GKey_K, GI_K fields Product_K, .... Well, my question is simple (I hope also my english!), how I can read only the products that have some reference on

Take(limit) list inside Groupby in Entity Framework

久未见 提交于 2020-01-11 07:05:48
问题 I need to take (for example, 2), 2 messages from a conversation I dont care about how my list looks like, but i want only 2 messages from id 1, 2 messages from id2, and go on example: id = idConversation Id | MessageId | Message ---|-----------|-------- 1 | 1 | "asd" 1 | 2 | "asd2" 1 | 3 | "asd3" 1 | 4 | "asd4" 2 | 5 | "asd5" 3 | 6 | "asd6" 3 | 7 | "asd7" 3 | 8 | "asd8" 3 | 9 | "asd9" 3 | 10 | "asd10" 4 | 11 | "asd11" 4 | 12 | "asd12" 4 | 13 | "asd13" and i want that Id MessageId Message ---|

Why does EF translate a Contains method call to Exists clause instead of In Clause?

回眸只為那壹抹淺笑 提交于 2020-01-11 06:55:30
问题 When I create this query: context.Orders.Where(x => context.Customers.Where(c => c.PersonID == 10002).Select(c => c.CustomerID.Value).Contains(x.CustomerID.Value)).ToList(); I Expect it to create a query like this: select * from Orders where CustomerID in (select CustomerID from Customers Where PersonID = 10002) But the generated query is equivalent to: select * from Orders o where Exists(select 1 from Customers c where c.PersonID = 10002 and c.CustomerID = o.CustomerID) this is a very simple

Cannot find my Entity Framework database

谁都会走 提交于 2020-01-11 06:55:10
问题 I am a little confused on the code first entity framework database. I created a new DbContext and class that I will be storing in that context, like this: namespace MyProject.Subproject.Something { public class MyItem { public string One { get; set; } public string Two { get; set; } [Key] public string Three { get; set; } public string Four { get; set; } } public class MyAppData : DbContext { public DbSet<MyItem> MyItems { get; set; } } } I know that it's working since I can do this without

LINQ Join query (with nullable ref between table)

青春壹個敷衍的年華 提交于 2020-01-11 06:48:11
问题 I have got 3 table. For instance Client , Company and Address . Client has got ref to Company. Company has got 2 nullable refs to Address (Billing and Shipping), so Address may not exist in some case. I need make join query, but in case when Company.BillingAddress or Company.ShippingAddress equals null , I don't get all data). I tried it (but it's wrong query): var res = (from client in context.Clients join clientCompany in context.Companies on client.ClientCompanyId equals clientCompany.Id

Cant Add controller which uses Class which is inherited from other class

▼魔方 西西 提交于 2020-01-11 06:45:26
问题 I'm using Entity Framework and MVC3, and my problem is that I can't scaffold Controllers if the class inherits from another Class. Example: This is Base Class using System; using System.Collections.Generic; namespace CRMEntities { public partial class Company { public int Id { get; set; } } } This is Lead Class (Child) using System; using System.Collections.Generic; namespace CRMEntities { public partial class Lead : Company { public Lead() { this.Status = 1; this.IsQualified = false; }

AutoMapper 3.1.1 and Entity Framework 6.1 Proxy objects

回眸只為那壹抹淺笑 提交于 2020-01-11 06:16:42
问题 I realized this has been asked already, but the solutions I've read don't seem to make a difference so far. I'm using Entity Framework 6.1 and AutoMapper 3.1.1. Taking the following objects: Company and CompanyListItem ; I try this: Mapper.Configure<Company, CompanyListItem>(); Well, when I try to do the actual mapping it crashed and burned with an exception that there's no mappings defined. I know this is caused because of the proxy objects created by Entity Framework. One solutions I've

AutoMapper 3.1.1 and Entity Framework 6.1 Proxy objects

丶灬走出姿态 提交于 2020-01-11 06:16:38
问题 I realized this has been asked already, but the solutions I've read don't seem to make a difference so far. I'm using Entity Framework 6.1 and AutoMapper 3.1.1. Taking the following objects: Company and CompanyListItem ; I try this: Mapper.Configure<Company, CompanyListItem>(); Well, when I try to do the actual mapping it crashed and burned with an exception that there's no mappings defined. I know this is caused because of the proxy objects created by Entity Framework. One solutions I've

Entity Framework complex type's columns naming convention

十年热恋 提交于 2020-01-11 06:00:12
问题 Using complex types the default column naming convention uses underscore. That means having type defined that way: [ColmplexType] public class Contact { string Email {get;set;} string Post {get;set;} } public EntityN { //... public Contact Contact {get;set;} } we will get columns named such way Contact_Email nvarchar(max) Contact_Post nvarchar(max) We of course could configure each column name separately using ColumnAttribute or Context.Properties mapping, but do we have a possibility to