Tag: entity framework 4

带有语句体的lambda表达式无法转换为nopCommerce 中的表达式树

我尝试在nopCommerce 3.0中创建一个linq连接查询。 我加入linq的两张桌子并写 代码成功了。 但视觉工作室的知识分子显示出错误 具有语句主体的lambda表达式无法转换为表达式树 请看下面的代码 var roles = _customerEventRoleRepository.Table.Where(c => c.EventId == selevent) .Join ( _customerRepository.Table, cev => cev.CustomerId, c => c.Id, (cev, c) => { var cust = new CustomerEventRolesModel(); cust.Id = cev.Id; cust.CustomerId = c.Id; cust.Customer = c.Email; cust.ContactName = c.GetAttribute(SystemCustomerAttributeNames.FirstName); cust.CompanyName = c.GetAttribute(SystemCustomerAttributeNames.Company); cust.Speaker = cev.IsSpeaker; cust.Sponsor = cev.IsSponser; return […]

尝试将新的EF4实体附加到ObjectContext,同时已附加其实体集合实体时出现问题

这有点难以解释,所以请耐心等待。 我有一个ASP.NET MVC 2项目,正在慢慢杀死我 ,我正在尝试获取表单数据并将其转换为实体来创建或更新,具体取决于具体情况。 最相关的部分(伪代码): Entity Game Scalar properties EntityCollection Platforms 基本工作流程是: 表单数据 – >绑定到DTO的模型 – >使用AutoMapper将DTO映射到EF4实体。 一切正常但有一个例外 – 我需要使用DTO中包含的原始整数索引数据创建或更新Game实体的Platforms EntityCollection。 所以,这是我一直在尝试的,这是行不通的: public AdminController(IArticleRepository articleRepository, IGameRepository gameRepository, INewsRepository newsRepository) { _articleRepository = articleRepository; _gameRepository = gameRepository; _newsRepository = newsRepository; Mapper.CreateMap() .BeforeMap((s, d) => { if (d.Platforms.Count > 0) { Platform[] existing = d.Platforms.ToArray(); foreach […]

entity framework:将nullable设置为false,但type仍然可以为空

此问题涉及在Visual Studio 2012中创建的新类库项目。 我已经将SQL Server视图添加到我的entity framework模型中。 在PromisedDate列的属性中,我已将Nullable从(None)更改为False因为此列中永远不会返回null值。 我已经仔细检查了select语句没有空值。 但是,即使在保存之后,关闭Visual Studio中所有打开的选项卡并完全清理并重建解决方案, PromisedDate仍然是DateTime? 我必须继续在代码中使用.Value来获取它的值。 令人沮丧的是,我做错了什么?! 以下是生成的.CS文件的屏幕截图:

DataBinding到计算字段

我遇到了一个小问题,我正在尝试将DataGrid的DataTextColumn绑定到计算字段。 WPF Student是一个Entity对象,只有一个小的加法。 TotalCosts不是db表中的字段,因此我为此创建了一个partial类。 public partial class Student { public Decimal TotalCosts { get { return (LodgingCosts + RegistrationCosts + TravelCosts + DiningCosts); } } } 我遇到的问题是,当您填写任何其他字段时,TotalCosts不会自动更新。 我的猜测是因为它没有被列为依赖属性。 如何为没有设置的属性解决此问题?

在我们的解决方案中将entity framework放在何处?

好的,我们有一个包含以下项目的解决方案: 商业逻辑 实体 数据访问 公用事业 unit testing 用户界面 它是一个非常大的企业级应用程序。 我的问题是,我们在哪里放置entity framework? 一方面,EF看起来像数据访问技术,应该进入DataAccess项目。 但另一方面,它会生成自己的实体,这些实体应放在我们已经很大的实体项目中。 哪个项目更适合entity framework? 是否有可能将实体与EF中的持久性逻辑分开?

如何为名称中带空格的列创建复杂的数据类型?

我有一个存储过程,返回列名称中带有空格和短划线的列。 我不能简单地使用“获取列信息”按钮为该存储过程自动生成复杂类型。 如何处理字段名称中的空格和破折号,因为它们不是C#中字段名称的合法字符?

其中一个主键值的类型与实体中定义的类型不匹配。 请参阅内部exception了解详细信

我有以下方法: – public ActionResult CustomersDetails(string[] SelectRight) { var selectedCustomers = new SelectedCustomers { Info = SelectRight.Select(GetAccount) }; return View(selectedCustomers); } private AccountDefinition GetAccount(string id) { return entities.AccountDefinition.Find(id); } 但它返回以下错误: – The type of one of the primary key values did not match the type defined in the entity. See inner exception for details. 在return entities.AccountDefinition.Find(id); […]

属性“text”是对象的关键信息的一部分,无法修改

所以我在数据库中有一个表,其中一列只是一个nvarchar(800)。 当我尝试做: try { UserTable = (from x in entities.userTable where x.uID == uID select x).Single(); UserTable.DateCreated = DateTime.Now; UserTable.text= newText; Update(UserTable); } 我在catch中得到了exception: “The property ‘text’ is part of the object’s key information and cannot be modified.” 当我查看表格时,我在“键”或“索引”下看不到任何内容。 所以这不是关键,我不明白为什么C#给我不正确的信息。 SQL Management Studio中没有任何内容说“文本”是关键字或索引。 我该怎么办?

ReferentialConstraint中的依赖属性映射到存储生成的列。 专栏:’ID’

当我尝试添加Venue对象并调用SaveChanges()时,我无法弄清楚为什么会出现此错误。 具有Venue对象的模型的唯一区别是它们与City的1到1..0关系。 City city = ProcessCityCache(ev, country, db); // After this call, ‘city’ is already persisted. venue = new Venue { TicketMasterURL = ev.VenueSeoLink, Name = Capitalize(ev.VenueName), City = city }; db.Venues.AddObject(venue); db.SaveChanges(); // Exception thrown here. 任何见解将不胜感激! (在自己的选项卡/窗口中打开图像以查看完整尺寸)

entity framework无法识别的唯一密钥

我有两个表, Reports和Visualizations 。 Reports有一个字段VisualizationID ,它通过外键指向Visualization的同名字段。 它还具有在该字段上声明的唯一键。 VisualizationID不可为空。 这意味着关系必须为0..1到1,因为每个 Reports记录必须具有与之关联的唯一的非空Visualizations记录。 entity framework不会这样看待它。 我收到以下错误: Error 113: Multiplicity is not valid in Role ‘Report’ in relationship ‘FK_Reports_Visualizations’. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *. 这有什么问题? 如何让EF识别正确的关系多样性?