EF4.1 Code First Complex Type as primary key

后端 未结 3 514
既然无缘
既然无缘 2021-01-04 08:49

I\'m currently trying to implement the repositories for my domain objects with the RC of Entity Framework 4.1 and its code first approach. Now I have a domain entity \"Voyag

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 09:25

    For an isolated class you could do a read-only workaround by adding a "get" method to your DbContext that does a SqlQuery<> and maps the table to the class internally (the old-fashioned way).

    I've worked up a minimal test-case here: https://github.com/timabell/ef-complex-pk

    e.g.

    public class TestDbContext : DbContext
    {
    
        public IEnumerable GetUberWidgets()
        {
            return Database.SqlQuery("select WidgetId, Name from Widgets")
                .Select(dto => new UberWidget
                {
                    UberWidgetId = new IdWrap { IdWrapId = dto.WidgetId },
                    Name = dto.Name
                });
        }
    }
    

提交回复
热议问题