EF 4,如何添加部分类 [英] EF 4, how to add partial classes
问题描述
我需要延长我的EF部分类,因为我想添加一些功能,以能够使用Oracle的序列,但是我真的不知道如何使用这个部分类的事情,我做了一个单独的cs文件和名称它作为我的自动生成的类之一,如下所示:
命名空间GlassStoreDAL
{
公共部分级车
{
私人诠释_sequences;
公众诠释序列
{
{返回_sequences; }
集合{_sequences =价值; }
}
}
}
现在我认为,我的BLL - 它引用GlassStoreDAL - 我能找到我的序列的属性,但显然不顺心的事,我会AP preciate这里任何帮助
下面是我的生成部分类,我应该有顺序性也有?
[EdmEntityTypeAttribute(NamespaceName =模型,NAME =CAR)
[序列化()]
[DataContractAttribute(IsReference =真)
公共部分类车:EntityObject
{
#地区的工厂方法
///<总结>
///创建一个新的CAR对象。
///< /总结>
///< PARAM NAME =ID>的ID属性的初始值小于/参数>
公共静态CAR CreateCAR(全球:: System.Decimal ID)
{
汽车汽车=新车();
cAR.ID = ID;
返回车;
}
#endregion
#地区的原始属性
///<总结>
///没有元数据文档。
///< /总结>
[EdmScalarPropertyAttribute(EntityKeyProperty = TRUE,ISNULLABLE = FALSE)]
[DataMemberAttribute()]
大众全球:: System.Decimal ID
{
得到
{
返回_ID;
}
组
{
如果(_ID!=值)
{
OnIDChanging(值);
ReportPropertyChanging(ID);
_ID = StructuralObject.SetValidValue(值);
ReportPropertyChanged(ID);
OnIDChanged();
}
}
}
私人全球:: System.Decimal _ID;
部分无效OnIDChanging(全球:: System.Decimal值);
部分无效OnIDChanged();
///<总结>
///没有元数据文档。
///< /总结>
[EdmScalarPropertyAttribute(EntityKeyProperty =假,ISNULLABLE =真)
[DataMemberAttribute()]
大众全球:: System.String名称
{
得到
{
返回_NAME;
}
组
{
OnNAMEChanging(值);
ReportPropertyChanging(NAME);
_NAME = StructuralObject.SetValidValue(价值,真实);
ReportPropertyChanged(NAME);
OnNAMEChanged();
}
}
私人全球:: System.String _NAME;
部分无效OnNAMEChanging(全球:: System.String值);
部分无效OnNAMEChanged();
///<总结>
///没有元数据文档。
///< /总结>
[EdmScalarPropertyAttribute(EntityKeyProperty =假,ISNULLABLE =真)
[DataMemberAttribute()]
大众全球:: System.String模型
{
得到
{
返回_model;
}
组
{
OnMODELChanging(值);
ReportPropertyChanging(模式);
_model = StructuralObject.SetValidValue(价值,真实);
ReportPropertyChanged(模式);
OnMODELChanged();
}
}
私人全球:: System.String _model;
部分无效OnMODELChanging(全球:: System.String值);
部分无效OnMODELChanged();
#endregion
#区域导航属性
///<总结>
///没有元数据文档。
///< /总结>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute(模型,
SYS_C009618,玻璃)
公共EntityCollection< GLASS>眼镜
{
得到
{
返回((IEntityWithRelationships)本).RelationshipManager。
GetRelatedCollection< GLASS>(Model.SYS_C009618,玻璃);
}
组
{
如果((值!= NULL))
{
((IEntityWithRelationships)本).RelationshipManager。
InitializeRelatedCollection< GLASS>(Model.SYS_C009618
玻璃,值);
}
}
}
#endregion
}
要总结大量评论踪迹......
检查分音被正确地连接在一起:
- 确保这两个类定义在同一个命名空间和程序集。
- 请他们确保至少有一个被声明为局部(大多数生成的类,包括EF产生的)。
- 检查,以确保新创建的部分可以看到previous成员,以确认谐音匹配。
其中客户端处于一个不同的二进制(这是这里的情况)
- 确保客户机项目的二进制/引用最新的(执行清理生成/删除了二进制文件复制/重建的参考),这取决于你的项目的情况。
有关该情况下,上次检查是最重要的,并解决了这个问题。
I needed to extend my EF partial classes, because I want to add some functionality to able to use Oracle's sequences , however I really don't know how to use this partial class thing, I made a seperate .cs file and name it as one of my auto-generated classes as follows:
namespace GlassStoreDAL
{
public partial class CAR
{
private int _sequences;
public int sequences
{
get { return _sequences; }
set { _sequences = value; }
}
}
}
Now I assumed that, on my BLL - which references GlassStoreDAL - I can find my "sequences" property , but apparently something goes wrong, I would appreciate any help here.
Here is my generated partial class , should I have the sequences property also there?
[EdmEntityTypeAttribute(NamespaceName="Model", Name="CAR")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class CAR : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new CAR object.
/// </summary>
/// <param name="id">Initial value of the ID property.</param>
public static CAR CreateCAR(global::System.Decimal id)
{
CAR cAR = new CAR();
cAR.ID = id;
return cAR;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Decimal ID
{
get
{
return _ID;
}
set
{
if (_ID != value)
{
OnIDChanging(value);
ReportPropertyChanging("ID");
_ID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ID");
OnIDChanged();
}
}
}
private global::System.Decimal _ID;
partial void OnIDChanging(global::System.Decimal value);
partial void OnIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String NAME
{
get
{
return _NAME;
}
set
{
OnNAMEChanging(value);
ReportPropertyChanging("NAME");
_NAME = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("NAME");
OnNAMEChanged();
}
}
private global::System.String _NAME;
partial void OnNAMEChanging(global::System.String value);
partial void OnNAMEChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String MODEL
{
get
{
return _MODEL;
}
set
{
OnMODELChanging(value);
ReportPropertyChanging("MODEL");
_MODEL = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("MODEL");
OnMODELChanged();
}
}
private global::System.String _MODEL;
partial void OnMODELChanging(global::System.String value);
partial void OnMODELChanged();
#endregion
#region Navigation Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("Model",
"SYS_C009618", "GLASS")]
public EntityCollection<GLASS> GLASSes
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.
GetRelatedCollection<GLASS>("Model.SYS_C009618", "GLASS");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.
InitializeRelatedCollection<GLASS>("Model.SYS_C009618",
"GLASS", value);
}
}
}
#endregion
}
To summarise the large comment trail...
Check that the partials are being attached together correctly:
- Make sure that both class definitions are in the same namespace and assembly.
- Make sure at least one of them is declared as partial (most generated classes are, including EF generated ones).
- Check to make sure that the newly created partial can see the previous members, to confirm the partials match up.
Where the client is in a different binary (which was the case here)
- Make sure the client projects binary/references are up to date (perform a clean build / delete the binary copy / recreate the reference), depending upon your project situation.
For this case, the last check was the most important and solved the problem.
这篇关于EF 4,如何添加部分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!