linq to entities - Entity Framework query - return unique values from child table -


I have an entity framework model and the data in related database tables is:

Question: How do I return to the unique form of model Ask the sales_type entities for a given person? (Person_sales table is too big, ~ 1 BB rows, other tables are relatively small)

Example: I want to know all the unique sales_type for a person "John". Will return 3 unique items: "Internal", "External" and "Mixed"

You can defintely person_id for person_sales table The index will be required and the query will appear in this way

  var salesTypes = (p.p. db.person in ps at db.person_sales p.id is equal to ps.person_id Ps.person_id in SM is equal to db.sales_mapping ps.sales_mapping_id sm.id in ST is equal to sm.sales_type_id st.id at db.sales_types, where p.name == "John" st.sales_name is selected ). Undoubtedly ();  

Generated will look like a SQL:

  SELECT [Distinct1]. [Sales_name] From AS [sales_name] [select [Extent4]. [Sales_name] AS [sales_name] FROM [dbo]. [Person] AS [Extent 1] Inner Join [DBO]. [Person_sale] [Extent 2 ] [Extra1]. [ID] = [Extension 2]. [Person_ID] Inner Join [DBO] [Sales_mapping] AS [extent2] at [extent2]. [Sales_mapping_id] = [extent3]. [ID] Inner Join [ DBO] as [sales_type] [extent3] at [extent4]. [Sales_type_id] = [extent4]. [ID] WHERE N'John '= [Extent1]. [Name]) as [specific 1] < / Code> 

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -