有没有替代方案:
Organizations.Include("Assets").Where(o => o.Id == id).Single()
Run Code Online (Sandbox Code Playgroud)
我希望看到类似的东西:
Organizations.Include(o => o.Assets).Where(o => o.Id == id).Single()
Run Code Online (Sandbox Code Playgroud)
避免使用硬编码字符串"Assets".
我有一个POCO(普通旧CLR对象)
public Foo
{
public virtual int Id { get; set; }
public virtual Dictionary<string, string> Stuff { get; set; }
public virtual string More { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
使用模型第一种方法(即我还没有数据模型),我将如何处理持久的Stuff(Dictionary)?
我正在尝试使用EF4创建一个通用方法来查找对象的主键.
例
public string GetPrimaryKey<T>()
{
...
}
Run Code Online (Sandbox Code Playgroud)
为了提供更多信息,我正在使用Tekpub StarterKit,下面是我试图启动和运行的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects;
using System.Data.Objects.ELinq;
using System.Data.Linq;
using Web.Infrastructure.Storage.EF4;
namespace Web.Infrastructure.Storage {
public class EFSession:ISession {
PuzzleEntities _db;//This is an ObjectContext
public EFSession() {
_db = new PuzzleEntities();
}
public void CommitChanges() {
_db.SaveChanges();
}
/// <summary>
/// Gets the table provided by the type T and returns for querying
/// </summary>
private ObjectSet<T> GetObjectSet<T>() where T:class {
return _db.CreateObjectSet<T>();
}
private T …Run Code Online (Sandbox Code Playgroud) 删除EF实体的所有集合项的正确方法是什么?在下面的代码中,DocumentItems是文档的相关文档项的集合.此代码在Clear()上进行,但在SaveChanges()上失败,因为相关项通过FK连接到其文档,FK是必需的.所以我猜他们在Clear()之后没有外键的情况下仍然悬浮在空中.
我是否通过在每个项目上调用Remove()的集合上的foreach循环来解决这个问题,还是有另一种方法?
// remove existing document items to prepare for refreshing them
existing.DocumentItems.Clear();
// adds new Document Items
PrepareInvoice(existing, collection);
_repository.SaveChanges();
Run Code Online (Sandbox Code Playgroud) 我首先使用实体框架代码CTP4.
是否有可能像NH 3中那样延迟加载非导航属性.
一个常见的例子是拥有一个包含二进制列的表.我只想在我的代码中明确要求该属性时检索此列的数据,例如image.ImageData
谢谢Ben
我们通过WCF数据服务公开域模型.该模型源自EF4,需要一些额外的工作才能使其成为通过Web服务发布所需的形式.
我想在EF4之外处理这个问题,以使我们的EDMX专注于模型,而不是它的用法.我的想法是创建一个专门用于Web服务的自定义"ServiceModel",并包含特定于服务的问题.
我的问题是如何在WCF数据服务中间最好地连接自动播放器.我正在使用WCF数据服务与ServiceModel的自定义(基于反射)提供程序.我在哪里可以将OData查询(对于ServiceModels)转换为EF4查询(对于DomainModels),并将结果映射回ServiceModels?
在asp.net mvc - model文件夹中创建模型是最佳做法.将这些模型与您的视图一起使用,并使用服务层将我的模型"调整"到EF模型.
或者你使用了另一种方法.这种方法的问题在于,我的(自制)模型大多数时候都是EF模型的副本(不干)
那么有人可以解释一下你的视图使用什么模型,因为它很令人困惑.model/viewmodel/Entityframeworkmodel ....
方案:
感谢您的回答所有猜测我现在正在重构一些事情!
select * from @t真的吗?有人告诉我它的谎言.
create procedure WorkIt
as
set nocount on
create table #pivot
(
Name varchar(30),
Value decimal,
Grade varchar(2)
)
insert into #pivot
select 'Repeating Pct', 1, 'K'
union all
select 'Repeating Pct', 2, '1'
union all
select 'Repeating Pct', 3, '2'
union all
select 'Repeating Pct', 4, '3'
union all
select 'Repeating Pct', 5, '4'
union all
select 'Repeating Pct', 6, '5'
union all
select 'Repeating Pct', 7, '6'
union all
select 'Repeating …Run Code Online (Sandbox Code Playgroud) 我需要一个有效的SQL Server 2008连接字符串,用于Entity Framework 4.1代码优先项目.我现在将它用于MVC 3.
现在它仍然很简单,只有1个项目,3个简单的模型类......
我只能找到其他一切,比如Sql Express,网络上的CE连接......
在web.config("ApplicationServices")中按名称查找它是可以的,因为当我尝试使用时,我得到了特定的错误.
我能得到的最好的是:
无法加载指定的元数据资源.
我也试着给它,metadata=res://MyWebProject/MyWebProject.csdl| ... 但没有成功.
所以它不会为我创建数据库 - 即使没有命中OnModelCreating(DbModelBuilder modelBuilder)方法.
如果我尝试使用像我在SQL Server Express中找到的"老式"连接,它会错过元数据.
感谢您的帮助.
configuration web-config entity-framework-4 entity-framework-4.1 asp.net-mvc-3
我正在尝试使用EF 4 Code First模式.我的初始化代码如下:
创建模型构建器:
private static DbModelBuilder CreateModelBuild()
{
var builder = new DbModelBuilder();
//add entity classes about 12 of them
builder.Conventions.Remove<IncludeMetadataConvention>();
return builder;
}
Run Code Online (Sandbox Code Playgroud)
创建会话:
private bool BuildSqlServerSession(DbModelBuilder builder)
{
var model =
builder.Build(new SqlConnection(@"connection string"));
var cm = model.Compile();
var context = new LittlePOSContext(cm);
var dbExists = context.Database.Exists();
_session = new EFSession(context);
return dbExists;
}
Run Code Online (Sandbox Code Playgroud)
这在我第一次运行代码时有效.但是当第二次运行并尝试使用context.Add(myEntity)我添加一个对象时,我得到以下异常:
Model compatibility cannot be checked because the EdmMetadata type was not
included in the model. Ensure that IncludeMetadataConvention has …Run Code Online (Sandbox Code Playgroud) c# ×3
.net ×2
asp.net-mvc ×1
automapper ×1
datamodel ×1
dictionary ×1
include ×1
linq ×1
primary-key ×1
string ×1
viewmodel ×1
web-config ×1