我可以实现实体框架5 TPT在Windows XP上? [英] Can I implement Entity Framework 5 TPT on Windows XP?
问题描述
的 EF5表每类型示例,我发现,如<一个href="http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-$c$c-first-ctp5-part-2-table-per-type-tpt.aspx"相对=nofollow>这个使用 [表(表名)]
属性的一类标记为定义的表。
Examples of EF5 Table Per Type that I have found, such as this one use the [Table("tablename")]
attribute to mark a class as defining a table.
当我加入这个属性我得到的错误:
When I add this attribute I get errors:
Error 1 The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?) E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DomainClasses\Classes.cs 599 6 DomainClasses
Error 2 The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?) E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DomainClasses\Classes.cs 599 6 DomainClasses
我也行
using System.ComponentModel.DataAnnotations;
在我的空间
和我使用的框架4,因为我想要的应用程序在Windows XP上运行。
And I am using framework 4 because I want the app to run on Windows XP.
[更新]我一看标记为可重复的<一个链接href="http://stackoverflow.com/questions/13340733/cannot-find-entity-framework-4-annotations">here,并因此增加了一个参考System.Data.Linq程序和使用将System.Data.Linq
[Update] I had a look at the link flagged as a possible duplicate here, and as a consequence added a reference to System.Data.Linq and a using System.Data.Linq
该错误消息是现在
Error 1 The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?) E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DomainClasses\Classes.cs 599 6 DomainClasses
Error 2 Using the generic type 'System.Data.Linq.Table<TEntity>' requires 1 type arguments E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DomainClasses\Classes.cs 599 6 DomainClasses
重要的是,我希望我的code工作在Windows XP中,第二个答案可能重复要求框架4.5
Importantly, I want my code to work on Windows XP , and the second answer to the possible duplicate requires framework 4.5
[更新] code是如下:
[Update] Code is as follows;
namespace SBD.Syrius.DomainClasses
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
[Table("Product")]
public class Product : LoggedEntity
{
[Required]
public string BuyUnitMeasure { get; set; }
[Required]
public Decimal BuyUnitQuantity { get; set; }
[Required]
public String Code { get; set; }
[Required]
public string Name { get; set; }
[Required]
public String SellUnitMeasure { get; set; }
[Required]
public Decimal SellUnitQuantity { get; set; }
public virtual Template Template { get; set; }
[Required]
public string UnitMeasure { get; set; }
public override string ToString()
{
return !string.IsNullOrEmpty(this.Name) ? this.Name : "Products";
}
}
public abstract class LoggedEntity
{
public int Id { get; set; }
public Guid RowId { get; set; }
[ConcurrencyCheck]
public int RowVersionId { get; set; }
public int SourceSiteNumber { get; set; }
}
}
[更新]
[Update]
我纠正了使用被 使用System.Data.Linq.Mapping;
I corrected the using to be using System.Data.Linq.Mapping;
现在我的错误是
System.Data.Linq.Mapping.TableAttribute' does not contain a constructor that takes 1 arguments
[更新]
[Update]
我也看了看没有接受答案的建议重复的问题。这是使用System.ComponentModel.DataAnnotations然而,这需要架构4.5,我不认为我可以使用,因为它不会在Windows XP上运行,而我需要在XP上运行。
I also looked at the not accepted answer to the suggested duplicate question. Which is to use System.ComponentModel.DataAnnotations however this requires framework 4.5 and I don't think I can use that because it wont run on Windows XP, and I need to run on XP.
[更新]
[update]
我开发的Windows 7,但应用程序需要在XP上运行。 我看到的例子中,我试图按照 <一href="http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-$c$c-first-ctp5-part-2-table-per-type-tpt.aspx"相对=nofollow>这是一次使用框架4.1流利
I am developing on Windows 7 but the application needs to run on XP. I see the example I am trying to follow Here it is again uses Framework 4.1 Fluent
我的问题是,我可以使用TPT上EF5在Windows XP上运行? 如果是这样,怎么样?
My question is Can I use TPT on EF5 to run on Windows XP? If so, how?
推荐答案
首先,删除将System.Data.Linq
命名空间,并且不使用 TableAttribute
从那里。这是LINQ到SQL而不是实体框架。
First of all, remove the System.Data.Linq
namespace and don't use the TableAttribute
from there. It is for LINQ-to-SQL and not for Entity Framework.
之间的版本4.1和5.0实体框架的表格
属性(其中包括)已被搬来搬去的命名空间和组件之间的一点:
Between version 4.1 and 5.0 of Entity Framework the Table
attribute (among others) has been moved around a bit between namespaces and assemblies:
根据不同的版本,你可以在follwing地方找到的属性:
Depending on the version you can find the attribute at the follwing places:
- 添加引用
EntityFramework.dll
组装到项目 - 添加
使用System.ComponentModel.DataAnnotations;
来code文件
- Add reference to
EntityFramework.dll
assembly to your project - Add
using System.ComponentModel.DataAnnotations;
to code file
- 添加引用
EntityFramework.dll
组装到项目 - 添加
使用System.ComponentModel.DataAnnotations.Schema;
来code文件
- Add reference to
EntityFramework.dll
assembly to your project - Add
using System.ComponentModel.DataAnnotations.Schema;
to code file
- 添加引用
System.ComponentModel.DataAnnotations.dll
组装到项目 - 添加
使用System.ComponentModel.DataAnnotations.Schema;
来code文件
- Add reference to
System.ComponentModel.DataAnnotations.dll
assembly to your project - Add
using System.ComponentModel.DataAnnotations.Schema;
to code file
在 TableAttribute
保留了其古老的目的和意义在所有版本。尤其是它的正确使用的TPT。
The TableAttribute
has kept its old purpose and meaning in all versions. Especially it's the correct one to use for TPT.
在你的情况下,你要支持Windows XP,但使用EF 5.0则需要.NET 4.0作为目标框架。为了得到正确的 TableAttribute
你要做的:
In your situation where you want to support Windows XP but use EF 5.0 you need .NET 4.0 as target framework. To get the correct TableAttribute
you have to do:
- 添加引用
EntityFramework.dll
组件项目(最可能是你有话) - 在检查该DLL(鼠标右键 - >属性)有版本号4.4。您可以潜在地具有错误的版本(5.0),如果你下载的NuGet包,而你的项目针对性的.NET 4.5。你后来改的框架.NET 4.0。在这种情况下删除参考目前
EntityFramework.dll
并添加引用,在该EntityFramework.dll
组装路径包\ EntityFramework.5.0.0 \ lib目录\ net40
根据您的解决方案文件夹 - 添加
使用System.ComponentModel.DataAnnotations.Schema;
来code文件
- Add reference to
EntityFramework.dll
assembly to your project (most likely you have that already) - Check if this DLL (right mouse -> Properties) has version number 4.4. You can potentially have the wrong version (5.0) if you downloaded the Nuget package while your project targetted .NET 4.5. and you changed the framework later to .NET 4.0. In that case remove the reference to the current
EntityFramework.dll
and add a reference to theEntityFramework.dll
assembly in the pathpackages\EntityFramework.5.0.0\lib\net40
under your solution folder - Add
using System.ComponentModel.DataAnnotations.Schema;
to code file
先说最后这三点,也许这是你必须追加 .Schema
到使用$ C你唯一的问题$ C>指令。
Start with the last of these three points, maybe it's your only problem that you have to append .Schema
to the using
directive.
这篇关于我可以实现实体框架5 TPT在Windows XP上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!