This must be something very simple, I just don't see it (and can not find the answer :(
I am trying to learn DevExpress controls and have read that eXpress Persistent Objects is recommended for O/R mapping.
1) I have an existing SQL Server Compact 4.0 database for which I generated ORM
2) I have a Winform with XtraGrid.GridControl gridControl1
3) In Form_Load event I have this code:
XPCollection cName = new XPCollection(typeof(WindowsFormsApplication1.DUzskv1r6.XPO_TableName));
int c = cName.Count; //didn't help...
cName.DisplayableProperties = "Name;Nr"; //choose columns to display
gridControl1.MainView.PopulateColumns();
gridControl1.DataSource = cName;
I have read that it using "delayed loading" - loading when it is necessary (http://documentation.devexpress.com/#XPO/clsDevExpressXpoXPCollectiontopic), but reading XPcollections record Count didn't do the trick as it was suggested.
As a result I get an empty gridControl1 with columns "Name" and "Nr".
Please help - what am I missing?
I think the issue is somewhere in your datalayer initialization.
You use XPCollection with default session, maybe you forgot to initialize it.
The best way is to specify the session is in the XPCollection contractor.
Related
When I've used Settings Designer before, I've been able to browse to find non-standard Types (e.g. uncommon enums etc) to use in my Settings via a "Browse" button at the bottom of the drop down under the "Type" column. I'm developing a WPF desktop application for .net Core and there is no Browse option as pictured below:
I did go into the code behind (Settings.Designer.cs.) and edit the code manually, but on saving, this just reverted to string. I'm guessing this may have something to do with settings also having an element in App.config and I notice it has a "serialiseAs" tag - didn't know what to put here. Exmaple of the code behind settings and App.config:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string UiTheme {
get {
return ((string)(this["UiTheme"]));
}
set {
this["UiTheme"] = value;
}
}
<userSettings>
<GameBoxer.WPF.Properties.Settings>
<setting name="UiTheme" serializeAs="String">
<value />
</setting>
</GameBoxer.WPF.Properties.Settings>
</userSettings>
Does anyone know how to bring back the 'Browse'?? Or, how to correctly do it in code?
I'm using Visual Studio 2022 Community
Thanks
UPDATE: So, I learn that this is "By Design" in VS2022 according to MS here. It's still present in VS2019! But they've taken it out of VS2022 and I can't figure how to do it in code. MS, you're one of my faves out the bunch, but sometimes, you're as mad as a box of frogs. unfortunately that link doesn't provide the poster with any alternatives other than "that's not a bug." Not very helpful, really.
As mentioned in the link you provided, this change was by design due to .NET Core and while I very strongly disagree with their stance on this - I'm assuming this was done because it could be quite fiddly to get your own types to work as expected, especially for new users.
One simple workaround if your custom data has several values, you can use string and simply write your own little parser using delimiters such as ;. You could also use StringCollection to achieve the same result.
Inconvenient, yes. But a simple solution nonetheless.
I sincerely hope Microsoft changes their stance on this and looks at reimplementing this as it worked remarkably well once you figured out the procedure to get it to serialize properly.
Edit:
Figured I might as well provide an example;
// Storing the Settings
// Parameter: Struct { Location(Point), Size(Point), Margin(Thickness) }
var settingString = $"{e.Location.X};{e.Location.Y};{e.Size.X};{e.Size.Y};{e.Margin.Left};{e.Margin.Top};{e.Margin.Right};{e.Margin.Bottom}";
Properties.Settings.Default.MySetting = settingString;
Properties.Settings.Default.Save();
// Parsing the Saved Setting
var settingString = Properties.Settings.Default.MySetting;
if (!String.IsNullOrWhiteSpace(settingString))
{
List<string> splitStrings = settingString.Split(';', StringSplitOptions.RemoveEmptyEntries).ToList();
List<double> parsedValues = new List<double>();
splitStrings.ForEach(x => parsedValues.Add(double.Parse(x)));
var location = new Point(parsedValues[0], parsedValues[1]);
var size = new Point(parsedValues[2], parsedValues[3]);
var margin = new Thickness(parsedValues[4], parsedValues[5], parsedValues[6], parsedValues[7]);
}
There's probably better ways of doing this, but I find this to be a very simple workaround and has worked great thus far.
I want to display data from Parse in a list from GamesScores class using Container in Codename One, this is what I've tried so far and it's not showing anything nor giving any errors:
Container container = findListCont();
container.setLayout(BoxLayout.y());
container.setScrollableY(true);
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
List<ParseObject> results = (List<ParseObject>) query.find();
System.out.println("Size: " + results.size());
container.addComponent(results, f);
Please help me out, I'm a new in Codename One. If there tutorials on it, please share or anything to help me achieve the desired results.
I'm actually shocked this isn't failing. You are using the add constraint to place the object result as a constraint and you add the form object into the container...
You need to loop over the results and convert them to components to add into the layout. It also seems that you are using the old GUI builder which I would recommend against.
Generally something like this rough pseudo code should work assuming you are using a box Y layout:
for(ParseObject o : results) {
MultiButton mb = new MultiButton(o.getDisplayValue());
f.add(mb);
}
f.revalidate();
I want to access two databases in Play Scala with anorm and Magic[T], (one is H2 and another is PostgreSQL). I just don't know how to config it...
I noticed that we can set another database connection in conf/application.conf
db_other.url=jdbc:mysql://localhost/test
db_other.driver=com.mysql.jdbc.Driver
db_other.user=root
db_other.pass=
However, how can I use it with Magic?
(I read the source code of Magic but don't understand it... my am a freshman of Scala)
Anyhow, if multiple database access is impossible with Magic[T] , I wish to do it with anorm, then how can I config it?
var sqlQuery = SQL( //I guess some config params should be set here, but how?
"""
select * from Country
"""
)
In play.api.db.DB it appears you can pass in a string of the name you defined in application.conf.
Then use one of the methods specified here: http://www.playframework.org/documentation/2.0/ScalaDatabase
# play.api.db.DB.class
def withConnection[A](name : scala.Predef.String)(block : scala.Function1[java.sql.Connection, A])(implicit app : play.api.Application) : A = { /* compiled code */ }
My question is simple, I have two databases with the same scehema, one is live database say DLive and other one is testbed say DTestBed....
However, I want to use the same database namespace for both database. How can I achieve that without changing namespace in my code all over? Sometimes you need to do builds for live and testbeds in the same day ! Its really hard to change big project namespaces everytime you build.
How can I just change the webconfig connection string and get it done?
Thanks,
STEP 1:
Open 'Setting.ttinclude' from your Subsonic project..
STEP 2:
Add new vairable beneath 'const string DatabaseName'..
const string DatabaseObjectName = "DatabaseObjectName";// This is the object that you use for calling Stored Procedures, Tables and etc...
like this;
DatabaseObjectNameDB db = new DatabaseObjectNameDB();
STEP 3:
Now open 'ActiveRecord.tt', 'StoredProcedures.tt', 'Context.tt' files from your Subsonic project..
STEP 4:
Replace '<#=DatabaseName#>' with '<#=DatabaseObjectName#>' in above opened files...
STEP 5:
Now 'Run Custom Tools', by Righ-Click your Subsonic project...
Here you go...
Problem solved!!
Regards,
Naeem
Are you using SubSonic2 or three?
With SubSonic 3 it's as simple as this:
var db = new YourProductDB("connectionstringname");
var db = new YourProductDB("Server=localhost;Database=devdb;Uid=root;", "MySql.Data.MySqlClient");
for the first row you have to have both connection strings defined in your web.config/app.config
I feel foolish asking such a fundamental question but it would be more foolish not to ask :)
I have been using SubSonic 2.x for years and love it (Thanks Rob and co.).
I have started a pilot project using SubSonic 3.0.0.4 and have chosen the LINQ T4 Templates (excuse me if I have the terminology wrong).
Now I am new to LINQ but I am doing OK working out how to build the queries.
What I am REALLY struggling with is how to create and update data with the new toolkit.
Previously it was super simple where I could:
'new' an object if I didn't have one
or Fetch or construct an existing one by id
set some properties
then 'Save()' it
Fantastic and saved me hours.
Now in the new toolkit some things seem to be the same like:
creating an object
setting some properties
but right now some things seem a lot harder like:
Loading an object seems to be:
db.Product.FirstOrDefault(x => ProductID.Id == 123);
Inserting seems to be:
db.Insert.Into<Northwind.Region>(
x => x.RegionID,
x => x.RegionDescription)
.Values(6, "Hawaii").Execute();
Updating an object seems even harder:
db.Update<Product>()
.Set(x => x.UnitPrice == 100, x => x.ProductName == "Test")
.Where(x => x.ProductID == 1).Execute();
The documentation (http://subsonicproject.com/docs/Linq_Updates) talks about using the Repository but that just doesn't exist/get generated with the T4 templates I am using.
So any help to let me know that:
I have obviously set this up wrong
I have no idea what I am doing and the way to do it is ... insert answer here
I understand it correctly and should just suck it up
would be greatly appreciated.
If any more info is needed please let me know.
Thanks in advance.
Mark
---- Update ----
To summarise the answer from Denis:
LINQ is a query language not an ORM
You can get to the Repository object via:
var repo = new SubSonic.Repository.SubSonicRepository(db);
Hmm.. I migrated one of my projects to the SubSonic 3 too but frankly have not had any troubles saving the entities. I use the same ActiveRecord techniques and it still works great for me. For example, to retrieve an entity I am issuing:
var product = new Product(p => p.Id == 123);
For inserting:
var product = new Product();
product.RegionID = 6;
product.RegionDescription = "Hawaii";
product.Save();
Updating:
product.UnitPrice = 100;
product.ProductName = "Test";
product.Save();
As you can see you can still use the same Save() method.
So, not really sure why you try to do that through the 'db' context even though it can be used too :) Am I missing something?