vita
vita copied to clipboard
Existing MsSql Views in DbFirst
In Vita 1.x vdbtool scripted the existing MsSql views, and they worked as expected. How can I script/use them in 3.x?
Another question: In 1.x I used lots of [NoColumn] fields from other Entity types. 3.x does not allows it. Is it intentional? For the latter I made the folloing quick fix:
private void BuildEntityMembers() {
foreach (var entInfo in Model.Entities) {
bool isTable = entInfo.Kind == EntityKind.Table;
var props = entInfo.EntityType.GetAllProperties();
EntityMemberInfo member;
foreach (var prop in props) {
EntityMemberKind kind;
if (TryGetMemberKind(entInfo, prop, out kind)) {
var memberAttrs = prop.GetAllAttributes(); //Quick fix
if (memberAttrs.Any(a=>a is NoColumnAttribute))//
kind = EntityMemberKind.Transient; //
member = new EntityMemberInfo(entInfo, kind, prop); //member is added to EntityInfo.Members automatically
member.Size = member.GetDefaultMemberSize();
// if it is table, or prop is declared on THIS entity (not inherited), take all attributes
if(isTable || prop.DeclaringType == entInfo.EntityType)
member.Attributes.AddRange(memberAttrs);
else {
// for inherited members on views we take only OneToMany and ManyToMany attributes;
// - we want to allow list properties on view entities (see vFictionBook view in Sample book store)
var listAttrs = memberAttrs.Where(a => a is ManyToManyAttribute || a is OneToManyAttribute).ToList();
member.Attributes.AddRange(listAttrs);
}
} //else - (kind not found) - do nothing, the TryGetMemberKind should have logged the message
}
}//foreach entType
}
With dbViews - so the problem is that vdbtool does not script them? I believe in general DbViews are supported, you can define them with LINQ, etc, there are unit tests for these About NoColumn - did not quite get what it means 'from other entity types'. I will look at NoColumn and what's going on there. In general, it should be just pure in-memory extra property on entity, right? - that's how you use it?
Views: Vita 1.x has IsView in the Entity attribute and vdbtool scripted the db views.
NoColumn: Exactly. I use them as "Transient" regardles of their type. E.g.:
[Entity(...)] public interface IX1 {...}
[Entity(...)] public interface IX2 { ... [NoColumn] IX1 X1 {get;set;} }
With [NoColumn] IX2.X1 is not a foreign key linked record.
ok, got it, will look at it, thanks for reporting it!
My solution for NoColumn: private void BuildEntityMembers() { foreach (var entInfo in Model.Entities) { bool isTable = entInfo.Kind == EntityKind.Table; var props = entInfo.EntityType.GetAllProperties(); EntityMemberInfo member; foreach (var prop in props) { EntityMemberKind kind; if (TryGetMemberKind(entInfo, prop, out kind)) { //-------------------------- var memberAttrs = prop.GetAllAttributes(); if (memberAttrs.Any(a=>a is NoColumnAttribute)) kind = EntityMemberKind.Transient; //-------------------------- member = new EntityMemberInfo(entInfo, kind, prop); //member is added to EntityInfo.Members automatically member.Size = member.GetDefaultMemberSize(); // var memberAttrs = prop.GetAllAttributes(); ------------ moved upper // if it is table, or prop is declared on THIS entity (not inherited), take all attributes if(isTable || prop.DeclaringType == entInfo.EntityType) member.Attributes.AddRange(memberAttrs); else { // for inherited members on views we take only OneToMany and ManyToMany attributes; // - we want to allow list properties on view entities (see vFictionBook view in Sample book store) var listAttrs = memberAttrs.Where(a => a is ManyToManyAttribute || a is OneToManyAttribute).ToList(); member.Attributes.AddRange(listAttrs); } } //else - (kind not found) - do nothing, the TryGetMemberKind should have logged the message } }//foreach entType }
thanks, I will look at it over weekend. I will be back at active VITA development soon, this Sept, and will address all issues reported, I promise
NoColumn attribute should be working now. With existing dbview it's a different story, looks like they are gone, did not think they are used much. I will look a little more, and see if it's possible to bring them back
Thanks for NoColumn! About views: they are very usefull in complex databases servicing rapidly changing busines requirements.
Views - will get to them and Db1st tool shortly