English 中文(简体)
B. 不同物体之间的数据完整性
原标题:Enforce data integrity between different object
问题回答

As in DB design you have to make your choices based on your business requirements. Means: You have to ask yourself questions of possible constellations - are all the songs on a CD from the same artist? No -> artist field on track, yes -> artist field on album - do you have to be able to get the album when you know a track, or just all the tracks from a specific album - ...

What you are doing is correct in the way that you reference from the Track object the name of the referenced Album. What is to mention: they do return the albums name, but just the name the album has in the moment of the GET. So if you assigned the AlbumName property to a visual control or whatever it will not update automatical when you change the Albums name.

if thats not what you want to hear ask more specific.

实际上,你不再从事协会活动。

在面向目标的方案规划中,你将目标而不是“钥匙”。 没有“外国钥匙”的概念。

如果物体B有母A,而A有unique ID<>em>,则通过设定unique ID而获得准B的母体:

B有母A:

public class A { public Guid ID { get; set; } }
public class B { public A Parent { get; set; } }

A someA = new A();
B someB = new B();
someB.Parent = someA;

由于“A”的含义可能与其他许多目标有关,因此从任何参考文献中改变同一目标,将修改该目标。

How to achieve integrity constraints? There re some design patterns, but one of most common one is Specification.

创建“核查”共同接口,采用一种可称为“检查”的方法,接受一种论点—— 标的检验标/>。 - 。 在实施过程中,这种方法将核查某些物体符合某些规格。

public interface ISpecification { bool Check(object some); }

public class Person { public string Name { get; set; } }

public class PersonSpecification : ISpecification
{
     public bool Check(object some) 
     {
          // Checks that some person won t be null and his/her name isn t null or empty
          return some != null && !string.IsNullOrEmpty(((Person)some).Name);
     }
} 

这是执行业务规则和(或)制约因素的非常简单和通用的样本。

有许多框架可以帮助你:

在一些项目中,I vetegrated NHibernate Validator和其他项目,一种基于Specification的模式的习俗解决办法,但比抽样更为复杂和灵活。

具体模式:





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...