I'm in weired situation. I read about context.Configuration.AutoDetectChangesEnabled = false; and decide to use it.
But I cant found it. the code is
using (DefaultCS db = new DefaultCS())
{
db.Configuration.AutoDetectChangesEnabled = false;
order.OrderTables = TableNo;
order.OrderMenus = oMenu;
db.Orders.AddObject(order);
db.SaveChanges();
}
I got error at db.Configuration which is ROS.DefaultCS does not contain a definition for 'Configuration' and no extension method 'Configuration' accepting a first argument of type 'ROS.DefaultCS' could be found (are you missing a using directive or an assembly reference?)
what I'm missing?
I'm using EF4.
Here is the answer: in Entity Framework 4 we should use db.Orders.MergeOption = MergeOption.NoTracking; instead of db.Configuration.AutoDetectChangesEnabled = false; which is only applicable in Entity Framework 5.
Code for EF4 and EF5
In EF4
db.Orders.MergeOption = MergeOption.NoTracking;
In EF5
db.Configuration.AutoDetectChangesEnabled = false;
The downgrade for EF4 is to set it for each Entity.
Related
I want to use NetworkInformation namespace and when I use system.net.networkInformation I'm getting error: "The type or namespace name 'NetworkInformation' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) "
I'm compact framework v2.0 or 3.5. compact framework should support networkInformation namespace?
I also tried to use this code:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "ipconfig.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
return output;
but the StandartOutput and redirectStandartoutput doesn't exist.
I'm trying to find out is the LAN is up or down. There is other way that I can use with compact framework?
You can do this with OpenNetCF's Smart Device Framework. I've used classes in this framework on several occasions when I find they are missing from CF2.0
See #ctacke's answer here:
The easiest way is to use OpenNETCF's SDF and look at the
OpenNETCF.Net.AdapterStatusMonitor class, which will raise events when
NDIS sends out notifications (like MEDIA_CONNECT and
MEDIA_DISCONNECT).
I am trying to fetch the keyword present in the Category using C# TBB to use the output in following DWT TBB.
For that I have a component with the Category field.
I am trying to write the following C# TBB to get the keyword value.
<%#Import NameSpace="Tridion.ContentManager.Templating.Expression" %>
try
{
string className = package.GetValue("Component.Fields.title");
KeywordField keywordField = package.GetKeywordByTitle(className);
package.PushItem("Class", package.CreateStringItem(ContentType.Text, keywordField.Value.Key));
}
catch(TemplatingException ex)
{
log.Debug("Exception is " + ex.Message);
}
But I am getting following compilation error.
Could not compile template because of: error CS0246: The type or namespace name 'KeywordField' could not be found (are you missing a using directive or an assembly reference?) error CS1061: 'Tridion.ContentManager.Templating.Package' does not contain a definition for 'GetKeywordByTitle' and no extension method 'GetKeywordByTitle' accepting a first argument of type 'Tridion.ContentManager.Templating.Package' could be found (are you missing a using directive or an assembly reference?)
Please suggest me how can I achieve it?
Thanks in advance
Af Jeremy suggested you should study API, I am providing you example of getting keywords from categories. Hope it may help
Include files
using Tridion.ContentManager;
using Tridion.ContentManager.CommunicationManagement;
using Tridion.ContentManager.Templating.Assembly;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.ContentManagement.Fields;
using Tridion.ContentManager.Templating;
Sample Code, You can use Key and Value from loop here as per your requirement.
string catID = package.GetByName("CategoryID").GetAsString();
TcmUri catURI = new TcmUri(int.Parse(catID), ItemType.Category, PubId);
var theCategory = m_Engine.GetObject(catURI) as Category;
catKeywords = GetCatKeywords(theCategory);
string strSelect = "<select>";
foreach (Keyword k in catKeywords)
{
k.Key // Keyowrd key
k.Value // KEyword Value
}
//keyword list
private IList<Keyword> GetCatKeywords(Category category)
{
IList<Keyword> keywords;
if (!Utilities.IsNull(category))
{
Filter filter = new Filter();
filter.BaseColumns = ListBaseColumns.IdAndTitle;
keywords = category.GetKeywords(filter);
if (!Utilities.IsNull(keywords))
{
return keywords;
}
}
return null;
}
The error message is absolutely clear what the problem is - there's no reference to the KeywordField class. You need to import the relevant namespace:
<%#Import NameSpace="Tridion.ContentManager.ContentManagement.Fields" %>
Also absolutely clear is the fact that the Package object doesn't have a method called GetKeywordByTitle. There is a GetByName method, but this is for retrieving a named item from the Package, not for getting an object from the respository.
Tridion.ContentManager.ContentManagement.Category does have a GetKeywordByTitle method, but to use this you will have to get the category first, which will likely mean having to know the URI of the category.
Perhaps you need to study the API docs some more?
"GetKeywordByTitle" is not a method on Package, its a method on Category.
Can't you just new-up Keyword?
string selectedKeyword= package.GetValue("Component.Fields.title");
Keyword keyword = new Keyword(selectedKeyword, engine.GetSession());
Cheers
When I update CustomerName using this code, CustomerDesc becomes NULL and vice versa. I Implemented the solution found in
EF4 Update Entity Without First Getting Entity
using (var dbMdl = new TestDBEntityModel())
{
Customer pr1 = new Customer();
pr1.CustomerId = 1;
if(pr1.EntityState == EntityState.Detached)
dbMdl.Customers.Attach(pr1);
// pr1.CustomerName = "Changed!";
pr1.CustomerDesc = "Changed!";
dbMdl.ObjectStateManager.ChangeObjectState(pr1, System.Data.EntityState.Modified);
dbMdl.SaveChanges();
}
After going through online tutorials, I solved it by removing dbMdl.ObjectStateManager.ChangeObjectState(pr1, System.Data.EntityState.Modified); and it worked as expected.
Im loading an Exe into my application using Assembly.LoadFile().
From that is it possible to get the Method of a particular class from that EXE.
Thanks in advance .
Try:
var assembly = Assembly.LoadFile("C:\path-to-some-app.exe");
var desiredType = assembly.GetType("SomeNamespace.SomeClass");
var methodInfo = desiredType.GetMethod("MethodName");
A number of things you can do with Reflection (Including constructors, method invocation etc.) Tutorial at : http://www.csharp-examples.net/reflection-examples/
I'm trying to create a treelistnode. The following below code getting an error:
private TreeListNode CreateTreeNode(EntityInfo entity)
{
CategoryInfo info = entity as CategoryInfo;
TreeListNode treeNode = new TreeListNode();
treeNode.SetValue("CatName", info.CatName);
treeNode.SetValue("CateCode", info.CateCode);
treeNode.SetValue("Id", info.Id);
treeNode.Tag = info.Id;
return treeNode;
}
Error
DevExpress.XtraTreeList.Nodes.TreeListNode.TreeListNode(int, DevExpress.XtraTreeList.Nodes.TreeListNodes)' is inaccessible due to its protection level
I need your help to create a separate treelistnode
Thanks!
You should use the TreeList's AppendNode method instead. Please also refer to the How to: Create Nodes in Unbound Mode in Code topic.