EF 4,如何添加部分类
我需要扩展我的 EF 部分类,因为我想添加一些功能以能够使用 Oracle 的序列,但是我真的不知道如何使用这个部分类,我制作了一个单独的 .cs 文件并将其命名为 one我的自动生成的类如下:
namespace GlassStoreDAL
{
public partial class CAR
{
private int _sequences;
public int sequences
{
get { return _sequences; }
set { _sequences = value; }
}
}
}
现在我假设,在我的 BLL(引用 GlassStoreDAL)上,我可以找到我的“序列”属性,但显然出了问题,我将不胜感激。
这是我生成的部分类,我应该也有序列属性吗?
[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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
总结大量的注释线索...
检查部分是否正确附加在一起:
如果客户端位于不同的二进制文件中(这里就是这种情况),
对于这种情况,最后一次检查是最重要的,解决了问题。
To summarise the large comment trail...
Check that the partials are being attached together correctly:
Where the client is in a different binary (which was the case here)
For this case, the last check was the most important and solved the problem.
您应该确保:
在生成的 EF 类中,您需要:
You should make sure that:
In your generated EF class you are required to:
在同一程序集中的单独文件中创建一个新类(尽管它不必是同一程序集),并确保它具有相同的命名空间。
如果它们都位于相同的程序集和命名空间中,那么您应该不会遇到任何问题。当您创建的新部分可以在源代码编辑器顶部的下拉列表中看到生成的 EF 类的属性和方法时,您就会知道您已经做对了。
Create a new class in a separate file in the same assembly (although it doesn't have to be the same assembly) and make sure it has the same namespace.
If they are both in the same assembly and namespace you shouldn't have any issues. You'll know that you've got it right when the new partial you've created can see the properties and methods of the generated EF class in the dropdown at the top of the source code editor.