{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6639","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6639/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6639/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6639/events","html_url":"https://github.com/aspnet/EntityFramework/issues/6639","id":180120610,"number":6639,"title":"Mapping FromSql to List<>","user":{"login":"gbfromhb","id":2523931,"avatar_url":"https://avatars.githubusercontent.com/u/2523931?v=3","gravatar_id":"","url":"https://api.github.com/users/gbfromhb","html_url":"https://github.com/gbfromhb","followers_url":"https://api.github.com/users/gbfromhb/followers","following_url":"https://api.github.com/users/gbfromhb/following{/other_user}","gists_url":"https://api.github.com/users/gbfromhb/gists{/gist_id}","starred_url":"https://api.github.com/users/gbfromhb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gbfromhb/subscriptions","organizations_url":"https://api.github.com/users/gbfromhb/orgs","repos_url":"https://api.github.com/users/gbfromhb/repos","events_url":"https://api.github.com/users/gbfromhb/events{/privacy}","received_events_url":"https://api.github.com/users/gbfromhb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/type-investigation","name":"type-investigation","color":"0052cc"}],"state":"open","locked":false,"assignee":{"login":"smitpatel","id":1528107,"avatar_url":"https://avatars.githubusercontent.com/u/1528107?v=3","gravatar_id":"","url":"https://api.github.com/users/smitpatel","html_url":"https://github.com/smitpatel","followers_url":"https://api.github.com/users/smitpatel/followers","following_url":"https://api.github.com/users/smitpatel/following{/other_user}","gists_url":"https://api.github.com/users/smitpatel/gists{/gist_id}","starred_url":"https://api.github.com/users/smitpatel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smitpatel/subscriptions","organizations_url":"https://api.github.com/users/smitpatel/orgs","repos_url":"https://api.github.com/users/smitpatel/repos","events_url":"https://api.github.com/users/smitpatel/events{/privacy}","received_events_url":"https://api.github.com/users/smitpatel/received_events","type":"User","site_admin":false},"assignees":[{"login":"smitpatel","id":1528107,"avatar_url":"https://avatars.githubusercontent.com/u/1528107?v=3","gravatar_id":"","url":"https://api.github.com/users/smitpatel","html_url":"https://github.com/smitpatel","followers_url":"https://api.github.com/users/smitpatel/followers","following_url":"https://api.github.com/users/smitpatel/following{/other_user}","gists_url":"https://api.github.com/users/smitpatel/gists{/gist_id}","starred_url":"https://api.github.com/users/smitpatel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smitpatel/subscriptions","organizations_url":"https://api.github.com/users/smitpatel/orgs","repos_url":"https://api.github.com/users/smitpatel/repos","events_url":"https://api.github.com/users/smitpatel/events{/privacy}","received_events_url":"https://api.github.com/users/smitpatel/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/23","html_url":"https://github.com/aspnet/EntityFramework/milestones/1.1.0","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/23/labels","id":2038420,"number":23,"title":"1.1.0","description":"","creator":{"login":"divega","id":1253414,"avatar_url":"https://avatars.githubusercontent.com/u/1253414?v=3","gravatar_id":"","url":"https://api.github.com/users/divega","html_url":"https://github.com/divega","followers_url":"https://api.github.com/users/divega/followers","following_url":"https://api.github.com/users/divega/following{/other_user}","gists_url":"https://api.github.com/users/divega/gists{/gist_id}","starred_url":"https://api.github.com/users/divega/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divega/subscriptions","organizations_url":"https://api.github.com/users/divega/orgs","repos_url":"https://api.github.com/users/divega/repos","events_url":"https://api.github.com/users/divega/events{/privacy}","received_events_url":"https://api.github.com/users/divega/received_events","type":"User","site_admin":false},"open_issues":26,"closed_issues":2,"state":"open","created_at":"2016-09-29T18:34:36Z","updated_at":"2016-10-06T00:31:46Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2016-09-29T18:05:13Z","updated_at":"2016-10-06T00:56:34Z","closed_at":null,"body":"I have created a model and have used a Stored Procedure and a View. It is returning two records with a few of the fields different if I query the stored procedure or the view form Sql Management Studio. When I use FromSql and tell it to map to a List<ActivationLink> it is duplicating the record twice and not giving me the two different records.\r\n\r\nHere is the store procedure:\r\n```SQL\r\n\tSELECT a.ActIvationId, pfl.FormId, f.Url, c.CustomerName, at.Description AS EventType, m.Market, al.StoreName, al.RetailerAddress, al.RetailerCity, al.RetailerState, al.RetailerZipcode, al.PhoneNumber, a.StartDate, \r\n\t\t   a.StartTime, a.EndTime\r\n\tFROM dbo.Activations AS a \r\n\t\tINNER JOIN dbo.ActivationTypes AS at ON a.ActivationTypeId = at.ActivationTypeId \r\n\t\tINNER JOIN dbo.ActivationLocations AS al ON a.ActivationLocationId = al.LocationId \r\n\t\tINNER JOIN dbo.ProjectMarkets AS pm ON al.ProjectMarketId = pm.ProjectMarketId \r\n\t\tINNER JOIN dbo.Markets AS m ON pm.MarketId = m.MarketId \r\n\t\tINNER JOIN dbo.Projects AS p ON pm.ProjectId = p.ProjectId \r\n\t\tLEFT OUTER JOIN dbo.ProjectFormsLink AS pfl ON p.ProjectId = pfl.ProjectId \r\n\t\tLEFT OUTER JOIN FormStack.Forms AS f ON pfl.FormId = f.FormId \r\n\t\tINNER JOIN dbo.Customers AS c ON p.CustomerId = c.CustomerID\r\n\tWHERE a.ActIvationId = @ActivationId\r\n```\r\n\r\nHere is the View\r\n```SQL\r\nSELECT        a.ActIvationId, pfl.FormId, f.Url, c.CustomerName, at.Description AS EventType, m.Market, al.StoreName, al.RetailerAddress, al.RetailerCity, al.RetailerState, al.RetailerZipcode, al.PhoneNumber, a.StartDate, \r\n                         a.StartTime, a.EndTime\r\nFROM            dbo.Activations AS a INNER JOIN\r\n                         dbo.ActivationTypes AS at ON a.ActivationTypeId = at.ActivationTypeId INNER JOIN\r\n                         dbo.ActivationLocations AS al ON a.ActivationLocationId = al.LocationId INNER JOIN\r\n                         dbo.ProjectMarkets AS pm ON al.ProjectMarketId = pm.ProjectMarketId INNER JOIN\r\n                         dbo.Markets AS m ON pm.MarketId = m.MarketId INNER JOIN\r\n                         dbo.Projects AS p ON pm.ProjectId = p.ProjectId LEFT OUTER JOIN\r\n                         dbo.ProjectFormsLink AS pfl ON p.ProjectId = pfl.ProjectId LEFT OUTER JOIN\r\n                         FormStack.Forms AS f ON pfl.FormId = f.FormId INNER JOIN\r\n                         dbo.Customers AS c ON p.CustomerId = c.CustomerID\r\n```\r\n\r\n\r\nGetting the following when queried outside of EF\r\n```\r\nActIvationId\tFormId\tUrl\r\n65\t                 2457400\thttps://xxxxxxxxx.com/forms/stillhouse_recap\r\n65\t                 2480856\thttps://xxxxxxxxxx.com/forms/stilhouse_check_in\t\r\n```\r\nHere is the EF query\r\n```C#\r\n         List<ActivationLink> links = await _dbContext.ActivationLinks\r\n            .FromSql(\"EXECUTE dbo.GetActivationLinksByActivationId {0}\", activationId).ToListAsync();\r\n```\r\nGetting this\r\n![image](https://cloud.githubusercontent.com/assets/2523931/18965554/93daf168-8632-11e6-8733-bc5c888a3930.png)\r\n\r\nNotice the FormId and Url should be different\r\n\r\nI have even put a unique index on FormID and it seem to not make a difference and still returned the identical records.\r\n```C#\r\n         builder.Entity<ActivationLink>()\r\n            .HasIndex(al => al.FormId).IsUnique();\r\n```\r\n \r\n\r\nThe versions are:\r\n  OS Name\tMicrosoft Windows 10 Pro Insider Preview - Version\t10.0.14936 Build 14936\r\n  Visual Studio 2015 - Version: 14.0.25431.01 Update 3\r\n  Microsoft.EntityFrameworkCore.SqlServer: 1.0.1\r\n\r\nAny advice would be greatly appreciated.\r\n\r\nAll the best,\r\nGlenn Byron"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/251840904","html_url":"https://github.com/aspnet/EntityFramework/issues/6639#issuecomment-251840904","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6639","id":251840904,"user":{"login":"smitpatel","id":1528107,"avatar_url":"https://avatars.githubusercontent.com/u/1528107?v=3","gravatar_id":"","url":"https://api.github.com/users/smitpatel","html_url":"https://github.com/smitpatel","followers_url":"https://api.github.com/users/smitpatel/followers","following_url":"https://api.github.com/users/smitpatel/following{/other_user}","gists_url":"https://api.github.com/users/smitpatel/gists{/gist_id}","starred_url":"https://api.github.com/users/smitpatel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smitpatel/subscriptions","organizations_url":"https://api.github.com/users/smitpatel/orgs","repos_url":"https://api.github.com/users/smitpatel/repos","events_url":"https://api.github.com/users/smitpatel/events{/privacy}","received_events_url":"https://api.github.com/users/smitpatel/received_events","type":"User","site_admin":false},"created_at":"2016-10-06T00:56:34Z","updated_at":"2016-10-06T00:56:34Z","body":"@gbfromhb - If `ActivationId` is PK for `ActivationLinks` then when EF tries to materialize data into ActivationLinks then it will do identity resolution and records with same `ActivationId` will be expected to be same and therefore 2nd record actually does not materialize and it will be same as the first one.\r\nEF will not have 2 different entity object with same identity (or PK) in context.\r\nIf you still want to have multiple records then you need to map results into non-entity type. It is being tracked by #1862 "}}
{"actor":{"display_login":"smitpatel"}}